我有一个CSV字段内有换行符。像:
COL1,COL2,COL3,COL4
...
1234567,"New Age Music","Line1
Line2
Line3: an so on",123-456-789
...
所以它实际上必须根据从标题中计算出的列数来读取。在Pandas / Python中有可能吗?
P.S。这是MSSQL 2008转储。也许有帮助。
答案 0 :(得分:0)
熊猫很聪明,可以为你做(如果它被正确引用):
In [74]: data
Out[74]: 'COL1,COL2,COL3,COL4\n1234567,"New Age Music","Line1\nLine2\nLine3: an so on",123-456-789'
In [75]: print(data)
COL1,COL2,COL3,COL4
1234567,"New Age Music","Line1
Line2
Line3: an so on",123-456-789
In [76]: pd.read_csv(io.StringIO(data))
Out[76]:
COL1 COL2 COL3 COL4
0 1234567 New Age Music Line1\nLine2\nLine3: an so on 123-456-789