Skip to main content

ads1

3.Use above dataframe and do the following:



Change the DataFrame Sales such that it becomes its transpose.

Display the sales made by all sales persons in the year 2018.

Display the sales made by Kapil and Mohini in the year 2019 and 2020.

Add data to Sales for salesman Nirali where the sales made are

[221, 178, 165, 177, 210] in the years [2018, 2019, 2020, 2021] respectively

Delete the data for the year 2018 from the DataFrame Sales.

Delete the data for sales man Shikhar from the DataFrame Sales.

Change the name of the salesperson Kamini to Rani and Kapil to Anil.

Update the sale made by Mohini in 118 to 150 in 2018.


import pandas as pd

#Creating DataFrame

d = {2018:[110,130,115,118],

     2019:[205,165,175,190],

     2020:[115,206,157,179],

     2021:[118,198,183,169]}

sales=pd.DataFrame(d,index=['Kapil','Kamini','Shikhar','Mohini'])

print("Transpose:")

print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

print(sales.T)

print("\nSales made by each salesman in 2018")


#Method 1

print(sales[2018])


#Method 2

print(sales.loc[:,2018])


print("Sales made by Kapil and Mohini:")

#Method 1

print(sales.loc[['Kapil','Mohini'], [2019,2020]])


#Method 2

print(sales.loc[sales.index.isin(["Kapil","Mohini"]),[2019,2020]])


print("Add Data:")

sales.loc["Nirali"]=[221, 178, 165, 177]

print(sales)


print("Delete Data for 2018:")

sales=sales.drop(columns=2018)

print(sales)



Sales.drop(columns=2018,inplace=True)

print(Sales)


sales=sales.drop("Shikhar",axis=0)

#sales.drop("kinshuk")

print(sales)


sales=sales.rename({"Kamini":"Rani","Kapil":"Anil"},axis="index")

print(sales)


sales.loc[sales.index=="Mohini",2018]=150

print(sales)


ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-