Pandas
index | values |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
data=pd.Series([1,2,3,4,5],index=['one','tow','three','four','five'])
population_dict={'bj':3000,'gz':1500,'sh':'2800'}
population_series=pd.Series(population_dict)
company={1:"Google",2:'Runoob',3:'Wiki'}
s_company=pd.Series(company,index=[1,2])
s_company
index | site | age |
---|---|---|
0 | 10 | |
1 | Runnoob | 12 |
c=[['Google',10],['Runoob',12]]
city=pd.DataFrame(c,columns=["site","age"])
city
site | age | |
---|---|---|
0 | 10 | |
1 | Runoob | 12 |
d=[['Google','Runoob'],[10,12]]
# e={'city':d[0],'age':d[1]}
# city=pd.DataFrame(e)
# e1=pd.Series(d[0])
# e2=pd.Series(d[1])
city=pd.DataFrame({'city':d[0],'age':d[1]})
city
index | city | age |
---|---|---|
0 | 10 | |
1 | Runoob | 12 |
population_dict={'beijing':3000,'shanghai':1200,'guangzhou':1800}
area_dict={'beijing':300,'guangzhou':200,'shanghai':180}
population_series=pd.Series(population_dict)
area_series=pd.Series(area_dict)
city=pd.DataFrame({'area':area_series,'population':population_series})
city
area | population | |
---|---|---|
beijing | 300 | 3000 |
guangzhou | 200 | 1800 |
shanghai | 180 | 1200 |
a={'a':1,'b':2}
b={'a':2,'b':3,'c':4}
c=pd.DataFrame([a,b])
c
a | b | |
---|---|---|
0 | 1 | 2 |
1 | 2 | 3 |
print(data)
data.fillna(method='ffill')
for i in data.columns:
data[i]=data[i].fillna(np.nanmean(data[i]))
data
a
print(a[a>a.mean()])
print(data[a>a.mean()])
print(data[a>a.mean()].loc[:,['a','b']])