【Pandas】读取或者写入csv文件会多出现一列----Unnamed:0
作者:互联网
注意:读取或者写入pandas文件时出现新的一列 'Unnamed:0'
解决方案1:
read_csv()时候,设置index_col=0即可。pd.read_csv(path,index_col=0)
解决方案2:
to_csv()时候,设置index=False。或者加上index=True, index_label=“id”df.to_csv(path,index=False)
或者df.to_csv(path,index=True, index_label="id")
import numpy as np
import pandas as pd
data1=pd.read_csv('test.csv')
data1.head(2)
data1=data1.drop('Unnamed: 0',1)
data1.to_csv('aaa.csv',index=False)
data1=pd.read_csv('aaa.csv')
data1.head(2)
data1=pd.read_csv('test.csv')
data1=data1.drop('Unnamed: 0',1)
data1.to_csv('aa.csv',index=True, index_label="id")
data1=pd.read_csv('aaa.csv')
data1.head(2)
标签:index,csv,pd,read,----,会多,Unnamed,data1 来源: https://blog.csdn.net/u013066730/article/details/111358023