我已经使用此函数将CSV导入到python中:
def import_csv(path):
return pd.read_csv(path, encoding='utf-16')
df = import_csv('path to CSV')
然而它已经导入了这样的数据:
col1 | col2 | col3 | col4 | col5 | col5 | col7 | col8 | col9
| | | | | | | | data1\data2\data3\..
| | | | | | | | data1\data2\data3\..
| | | | | | | | data1\data2\data3..
...
应该看起来像:
col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9
data1|data2 |data3 |data4 |data5 |data6 |data7 |data8 |data9
data1|data2 |data3 |data4 |data5 |data6 |data7 |data8 |data9
...
我尝试将功能更改为:
def import_csv(path):
return pd.read_csv(path, encoding='utf-16', sep="\n")
但没有区别。
编辑:我刚刚list(df.columns)
,所有列都作为一个列表项出现,打印为:['col1\col2\col3\col4\col5\col6\col7\col8\col9']
答案 0 :(得分:1)
您的CSV似乎被标签分隔,而不是逗号。像pd.read_csv(path, encoding='utf-16', sep="\t")
一样将分隔符指定为here : learn.forge.viewmodels/www/js/ForgeViewer.js
。这应该有用。