Page 97 - Informatics_Practices_Fliipbook_Class12
P. 97
5. Use the DataFrame created in Question 4 above to do the following:
a. Display the row labels of Sales.
b. Display the column labels of Sales.
c. Display the data types of each column of Sales.
d. Display the dimensions, shape, size and values of Sales.
e. Display the last two rows of Sales.
f. Display the first two columns of Sales.
g. Create a dictionary using the following data. Use this dictionary to create a DataFrame Sales2.
2018
Madhu 160000
Kusum 110000
Kinshuk 500000
Ankit 340000
Shruti 900000
h. Check if Sales2 is empty or it contains data.
Ans. a. print(Sales.index)
b. print(Sales.columns)
c. print(Sales.dtypes)
d. print("Dimensions:",Sales.ndim)
print("Shape:",Sales.shape)
print("Size:",Sales.size)
print("Values:",Sales.values)
e. print(Sales.tail(2))
f. print(Sales[[2014,2015]])
print(Sales.iloc[:, 0:2] )
g. dict2={2018:[160000,110000,500000,340000,900000]}
Sales2=pd.DataFrame(dict2,index=["Madhu","Kusum","Kinshuk", "Ankit","Shruti"])
print(Sales2)
h. print(Sales2.empty)
6. Use the DataFrame created in Question 4 above to do the following:
a. Append the DataFrame Sales2 to the DataFrame Sales.
b. Change the DataFrame Sales such that it becomes its transpose.
c. Display the sales made by all sales persons in the year 2017.
d. Display the sales made by Madhu and Ankit in the year 2017 and 2018.
e. Display the sales made by Shruti 2016.
f. Add data to Sales for salesman Sumeet where the sales made are [196.2, 37800, 52000, 78438, 38852] in the years
[2014, 2015, 2016, 2017, 2018] respectively.
g. Delete the data for the year 2014 from the DataFrame Sales.
h. Delete the data for sales man Kinshuk from the DataFrame Sales.
i. Change the name of the salesperson Ankit to Vivaan and Madhu to Shailesh.
j. Update the sale made by Shailesh in 2018 to 100000.
k. Write the values of DataFrame Sales to a comma separated file SalesFigures.csv on the disk. Do not write the row labels
and column labels.
l. Read the data in the file SalesFigures.csv into a DataFrame SalesRetrieved and Display it. Now update the row labels and
column labels of SalesRetrieved to be the same as that of Sales.
Data Handling using Pandas DataFrame 83

