[英]Python pandas read a csv from one column then seperate columns
我有一個需要根據問題數量進行分隔的csv,目前我的代碼出現錯誤
dfcleancsv = pd.read_csv('InitialQuerydataOpen.csv', sep=",")
ValueError: Expected 1 fields in line 1609, saw 55
我有的
Column1 Column2
1583 FIT-491
1584 FIT-4276,"TC 1140.0024, 1140.0025, 1140.0026, 1140.0179, 1140.018"
我想要的是
Column1 Column 2 Column3 Column4 Column5 Column6 Column7
1583 FIT-491
1584 FIT-4276 1140.0024 1140.0025 1140.0026 1140.0179 1140.018
干得好:
with open('test.txt') as f:
data = {i:txt.strip().split(',') for i,txt in enumerate(f.readlines())}
df = pd.DataFrame.from_dict(data, orient='index')
print(df)
## -- End pasted text --
0 1 2 3 4 5 6
0 1583 FIT-491 None None None None None
1 1584 FIT-4276 1140.0024 1140.0025 1140.0026 1140.0179 1140.018
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.