CParseError读取pandas中的csv文件

时间:2016-08-05 15:25:55

标签: python csv pandas dataframe

获取CParcerError:错误 - 数据的错误,预计第6行中的4个字段,在阅读以下带有pandas的csv文件时看到5-

1   0.707   2881292.08  992607.12   57.46   57.46   *BB 2.9028
2   1.043   1187965.81  496643.82   23.69   23.69   *BB 2.392
3   1.685   477470.92   142957.85   9.52    9.52    *BB 3.3399
4   2.755   201900.68   36276.04    4.03    4.03    *BB 5.5657
5   3.196   206744.22   31258.27    4.12    4.12    *BB 6.6141
6   5.953   29364.36    2362.28     0.59    0.59    *BB 12.4305


def csv_new(folder):
    for filename in os.listdir(folder):
        infilename = os.path.join(folder,filename)
        data = pd.read_csv(infilename, sep = ',', index = None)
        new_filename = ".....fid/new.csv" %(filename)
        data.to_csv(new_filename)

csv_new('....fid/')

我已经调试了很长时间但仍然没有成功。我发现数据及其结构没有问题。我不知道为什么我得到CParseError?

从txt文件转换为csv:

def txt_to_csv(folder):
    for filename in os.listdir(folder):
        infilename = os.path.join(folder,filename)
        data = pd.read_csv(infilename, sep ='/t', header = None, skiprows = 2, index_col = 0, engine = 'python')
        new_data = data[24:30]
        new_filename = "........fid/%s.csv" %(filename)
        new_data.to_csv(new_filename, sep = '"', header = None)

0 个答案:

没有答案