Pandas Questions
Pandas Questions
b)
Write a small python code to create a dataframe with headings(a and b)
from the list given below : [[1,2],[3,4],[5,6],[7,8]]
3.import pandas as pd
d=[[‘S101’,’Amy’,70],[‘S102’,’Bandhi’,69],[‘S104’,’Cathy’,75]],[‘S105’,’G
undaho’,82]]
df=pd.DataFrame(d,columns=[‘ID’,’Name’,’Marks’])
print(df)
b)import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4]], columns = ['a','b'])
df2 = pd.DataFrame([[5, 6], [7, 8]], columns = ['a','b'])
df = df.append(df2)
4. a b
first 10 20
second 6 32
a b1
first 10 NaN
second 6 NaN
5.import pandas as pd
import numpy as np
df1 = pd.DataFrame({'mark1':[30,40,15,40], 'mark2':[20,45,30,70]})
df2 = pd.DataFrame({'mark1':[10,20,20,50], 'mark2':[15,25,30,30]})
print(df1)
print(df2)
(i) print(df1.add(df2))
(ii) print(df1.subtract(df2))
(iii) df1.rename(columns={'mark1':'marks1'}, inplace=True)
print(df1)
(iv) df1.rename(index = {0: "zero", 1:"one"}, inplace = True)
print(df1)
6.import pandas as pd
t=[31,24,30,26,27,26,28]
temp1=pd.Series(t,index=[‘Monday’,’Tuesday’,’Wednesday’,’Thursday’
,’Friday’,’Saturday’,’Sunday’])
print(temp1)
7.print(temp1.head(3))
ii) print(temp1.tail(3))
iii) print(temp1.mean())
8.import pandas as pd
s=pd.Series([22,13,44])
print(s.describe)
9.import pandas as pd
import numpy as np
d=np.arange(5,51,5)
s=pd.Series(d)
print(s)
10. import pandas as pd
import numpy as np
s=pd.Series([22,13,44])
print(s)
d=np.arange(5,51,5)
s1=pd.Series(d)
print(s1)
df=pd.DataFrame({“col”:s,”col2”:s1})
print(df)