Q. Use the DataFrame created in Question 9 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.
Answer :-
a =
print(Sales.T.append(Sales2.T).T)
b =
print(Sales.T)
c =
print(Sales['2017'])
d =
print(Sales['2017']['Madhu']) print(Sales['2018']['Madhu']) print(Sales['2017'][‘ Ankit’]) print(Sales['2018'][“ Ankit”])
e =
print(Sales['2017'][‘ Shruti’])
g =
del Sales['2014']
h =
Sales=Sales.drop('Kinshuk', axis=0)]
i =
Sales.rename({'Ankit':'vivaan','Madhu':'Shailesh'}, axis='index')
j =
Sales['2018']['Shailesh']= 100000
k =
Sales.to_csv( 'e:/SalesFigures.csv', sep = ',', header = False, index= False)
l =
SalesRetrieved = pd.read_csv('e:/SalesFigures.csv',sep =",",names=['2014', '2015', '2016', '2017']) SalesRetrieved.index=['Shailesh','Kusum','Kinshuk','vivaan','shruti']
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )