1.Write a Python program to convert a dictionary to a Pandas series. Sample Series:
Dictionary:{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 800}
Converted series:
a 100
b 200
c 300
d 400
e 800
dtype: int64
import pandas as pd
dc={'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 800}
sr=pd.Series(data=dc)
print(sr)
2.Create a panda’s series from a numpy array.(Take array values of your choice).
import pandas as pd
import numpy as np
ls=[12,13,14,15,16,17]
arr=np.array(ls)
sr=pd.Series(data=arr)
print(sr)
3. Write a Pandas program to add, subtract, multiple and divide two Pandas Series.
import pandas as pd
ls=[10,11,12,13,14,15]
ls1=[1,2,3,4,5,6]
sr1=pd.Series(ls)
sr2=pd.Series(ls1)
print(sr1)
print(sr2)
print("SUM: \n",sr1+sr2)
print("Diffrence: \n",sr1-sr2)
print("Multiply: \n",sr1*sr2)
print("Divide: \n",sr1+sr2)
4.Write a program to sort the element of Series S1 into S2(Take any series of of choice).
import pandas as pd
ls=[10,1,13,12,5,15]
sr1=pd.Series(ls)
print("Original Series: \n",sr1)
sr2=sr1.sort_values()
print("Sorted Series: \n", sr2)
5.Create two dataframes using the following two Dictionaries. Merge the two dataframes and append the second dataframe as a new column to the first dataframe on the basis of the manufacturing company’s name.
Car_Price = {'Company': ['Toyota', 'Honda', 'BMW', 'Audi'], 'Price': [23845, 17995, 135925 , 71400]}
car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMW', 'Audi'], 'horsepower': [141, 80, 182 , 160]}
import pandas as pd
Car_Price = {'Company': ['Toyota', 'Honda', 'BMW', 'Audi'], 'Price': [23845, 17995, 135925 , 71400]}
car_Horsepower = {'Company': ['Toyota', 'Honda', 'BMW', 'Audi'], 'horsepower': [141, 80, 182 , 160]}
df1=pd.DataFrame(Car_Price)
df2=pd.DataFrame(car_Horsepower)
print(df1,"\n")
print(df2,"\n")
print("DataFrame Merge operation \n",df1.merge(df2))
6.Create a Data Frame Expenditure where each row contains the item category, item name, and expenditure.
Item Category | Item name | Expenditure |
---|---|---|
Groceries | Rice | 1500 |
Groceries | Milk | 1000 |
Groceries | Vegetable | 2500 |
Cloth | T shirt | 1000 |
Cloth | Jeans | 2500 |
Maintenance | Electricity | 500 |
Maintenance | Water | 9000 |