美文网首页
Python Pandas (1)

Python Pandas (1)

作者: 八喜不破百 | 来源:发表于2019-04-03 19:11 被阅读0次

import pandas as pd

Series

a = pd.Series([1,2,3,4],index=['a','b','c','d'])
.reindex #改index
.drop #删除index

dataframe 二位数组

import pandas as pd
a = pd.Series([1,2,3,4],index=['a','b','c','d'])
b = pd.Series([2,23,3,4],index=['a','b','c','d'])
c= pd.Series([6,2,37,4],index=['a','b','c','d'])
m={'x':a,'y':b,'z':c}
n=pd.DataFrame(m)
x y z
a 1 2 6
b 2 23 2
c 3 3 37
d 4 4 4

数据清洗

数据提取

print (n.iloc[1,1])
print(n.iloc[0:2,:])
print(n.loc['b','x'])

新增行

f=[5,5,7]
n.loc['f',:]=f

顺序

n=n.sort_values(by=['x'],ascending=False)

相关文章

网友评论

      本文标题:Python Pandas (1)

      本文链接:https://www.haomeiwen.com/subject/whoubqtx.html