PROGRAM
Creating a DataFrame
import pandas as pd
list1=[10,20,30,40]
table=pd.DataFrame(list1)
print(table)
data=[{'a':1,'b':2},{'a':2,'b':4,'c':8}]
table1=pd.DataFrame(data)
print(table1)
table2=pd.DataFrame(data,index=['first','second'])
print(table2)
data1={'one':pd.Series([1,2,3],index=['a','b','c']),'two':pd.Series([1,2,3,4],index=['a','b','c','d'])
}
table3=pd.DataFrame(data1)
print(table3)
DataFrame – Addition & Deletion of Columns
table3['three']=pd.Series([10,20,30],index=['a','b','c'])
print(table3)
del table3['one']
print(table3)
table3.pop('two')
print(table3)
DataFrame – Addition & Deletion of Rows
print(table3.loc['c'])
print(table3.iloc[2])
OUTPUT
0
0 10
1 20
2 30
3 40
a b c
0 1 2 NaN
1 2 4 8.0
a b c
first 1 2 NaN
second 2 4 8.0
one two
a 1.0 1
b 2.0 2
c 3.0 3
d NaN 4
one two three
a 1.0 1 10.0
b 2.0 2 20.0
c 3.0 3 30.0
d NaN 4 NaN
two three
a 1 10.0
b 2 20.0
c 3 30.0
d 4 NaN
three
a 10.0
b 20.0
c 30.0
d NaN
three 30.0
Name: c, dtype: float64
three 30.0
Name: c, dtype: float64