Informatics Practices
Carefully observe the following code :
import pandas as pd
Year1 = {'Q1': 5000, 'Q2': 8000, 'Q3': 12000, 'Q4': 18000}
Year2 = {'A': 13000, 'B': 14000, 'C': 12000}
totSales = {1: Year1, 2: Year2}
df = pd.DataFrame(totSales)
print(df)
Answer the following :
(i) List the index of the DataFrame df.
(ii) List the column names of DataFrame df.
Python Pandas
8 Likes
Answer
(i) The index of the DataFrame df is: ['Q1', 'Q2', 'Q3', 'Q4', 'A', 'B', 'C'].
(ii) The column names of the DataFrame df are: [1, 2].
Answered By
5 Likes
Related Questions
What advantages does dataframe offer over series data structure ? If you have similar data stored in multiple series and a single dataframe, which one would you prefer and why ?
Create a DataFrame in Python from the given list :
[['Divya', 'HR', 95000], ['Mamta', 'Marketing', 97000], ['Payal', 'IT', 980000], ['Deepak', 'Sales', 79000]]
Also give appropriate column headings as shown below :
Name Department Salary 0 Divya HR 95000 1 Mamta Marketing 97000 2 Payal IT 980000 3 Deepak Sales 79000 Given :
import pandas as pd d = {'one' : pd.Series([1., 2., 3.], index = ['a', 'b', 'c']), 'two' : pd.Series([1., 2., 3., 4.], index = ['a', 'b', 'c', 'd'])} df = pd.DataFrame(d) df1 = pd.DataFrame(d, index = ['d', 'b', 'a']) df2 = pd.DataFrame(d, index = ['d', 'a'], columns = ['two', 'three']) print(df) print(df1) print(df2)What will Python show the result as if you execute above code ?
From the DataFrames created in previous question, write code to display only row 'a' from DataFrames df, df1, and df2.