说明
1、python+data+analysis的组合缩写,是python中以numpy和matplotlib为基础的第三方数据分析库
2、共同构成python数据分析的基本工具包,享有三个剑客的名字。
安装
打开cmd,依次输入以下三个命令。
pipinstallpandas-ihttps://pypi.tuna.tsinghua.edu.cn/simple pipinstallnumpy-ihttps://pypi.tuna.tsinghua.edu.cn/simple pipinstallmatplotlib-ihttps://pypi.tuna.tsinghua.edu.cn/simple
pandas选择数据
importpandasaspd
importnumpyasnp
dates=pd.date_range('20210301',periods=6)
df1=pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])
print(df1)
pandas赋值及操作
importpandasaspd
importnumpyasnp
dates=pd.date_range('20210301',periods=6)
df1=pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])
print(df1)
pandas对于空数据的处理
importpandasaspd
importnumpyasnp
dates=pd.date_range('20210301',periods=6)
df1=pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])
df2=pd.DataFrame(df1,index=dates,columns=['A','B','C','D','E','F'])
s1=pd.Series([3,4,6,7],index=dates[:4])#对第一个到第四个数据进行赋值
s2=pd.Series([32,5,2,1],index=dates[2:])#对第三个数据到最后一个数据进行赋值
df2['E']=s1
df2['F']=s2
print(df2)
以上就是python中pandas的知识点整理,希望对大家有所帮助。
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
上一篇
下一篇