pandas 基础

pandas 基础

1. 文件读入、写入

df = pd.read_csv(r'C:\Coding\DataAnalyse\joyful-pandas-master\joyful-pandas-master\data\table.csv')
print(df.head())

df_txt = pd.read_table(r"C:\Coding\DataAnalyse\joyful-pandas-master\joyful-pandas-master\data\table.txt")
print(df_txt)

df_excel = pd.read_excel(r"C:\Coding\DataAnalyse\joyful-pandas-master\joyful-pandas-master\data\table.xlsx")
print(df_excel.head())

df.to_csv(r"C:\Coding\DataAnalyse\joyful-pandas-master\joyful-pandas-master\data\new_table.csv")

df.to_csv(r"C:\Coding\DataAnalyse\joyful-pandas-master\joyful-pandas-master\data\new_table.csv",index=False)

文件读取写入

2、Series基础

s = pd.Series(np.random.randn(5),index=['a','b','c','d','e'], name="This is the first Series")
print(s)
print(s.name)
print(s.index)
print(s.dtype)
print(s['b'])
print(s.mean)
print([attr for attr in dir(s) if not attr.startswith('_')])

在这里插入图片描述

3、DateFrame基础

df = pd.DataFrame({'col1':list('abcde'), 'col2':range(5,10), 'col3':[1.3,2.5,3.6,4.6,5.8]},
                 index=list('一二三四五'))
print(df)
print(df['col1'])
print(type(df))
print(type(df['col1']))
# df.rename(index={'一':"one", columns ={"col1":"new_col1"}})
tt = df.rename(index={'一':'one'}, columns={'col1':'new_col1'})
print(tt)
print(df.index)
print(df.columns)
print(df.values)
print(df.shape)
print(df.mean())

df1 = pd.DataFrame({'A':[1,2,3]},index=[1,2,3])
df2 = pd.DataFrame({'A':[1,2,3]},index=[3,1,2])
print(df1-df2) 

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值