微信公众号:Python集中营简单的事重复,重复的事坚持做,坚持的事用心做;你的动力就是我的动力,如果这篇文章对你有帮助,请点击它!sepcustomseparator1file_path="data.csv"23#返回DataFrame数据结构,sep参数自定义分隔符45df=pd.read_csv(file_path,sep=',')67print(df.head(5))headerfrom定义headerrow1#返回DataFrame数据结构,header参数定义了哪一行数据是header23df=pd.read_csv(file_path,header=0)45print(df.head(5))注意:前面的headerrows都是该行data会自动删除names自定义列标签1#返回DataFrame数据结构,names参数自定义列标签23df=pd.read_csv(file_path,names={'name','age','score'})45print(df.head(5))index_col自定义索引1#返回DataFrame数据结构,index_col参数自定义列标签作为索引23df=pd.read_csv(file_path,index_col='score')45print(df.head(5))skiprows跳过行读取1#返回DataFrame数据结构,skiprows参数自定义读取时跳过多少行23df=pd.read_csv(file_path,skiprows=10)45print(df.head(5))savefile1#savefileandIgnoretheindex23df.to_csv('new_data.csv',index=False)更多精彩,关注微信公众号【Python集中营】,关注python技术栈,数据获取,交流社区,干货分享,期待你的加入~
