ID,name,category,main_category,currency,deadline,goal,launched,pledged,state,backers,country,usd pledged
1009317190,French Cuisine, A Traditional Experience,Cookbooks,Food,USD,2014-09-08 00:46:23,13730,2014-08-09 03:16:02,3984,failed,46,US,3984
我使用pandas.read_csv()
将上面的csv文件加载到数据帧。但是,我的输出是这样的:
问题:如何忽略French Cuisine
和A Traditional Experience
之间的逗号,并将它们读入同一列?
答案 0 :(得分:1)
您可以按照以下步骤实现所需的目标:
第一步:
df['name'] = df['name']+df['category']
第二步:
data1 = df.iloc[:, :2] # dataframe with columns 'ID' and 'name'
data2 = df.iloc[:, 2:].T.shift(-1,axis=0).T # Shifting multi-column data to the left
data = pd.concat([data1, data2], axis=1) # concat dataframes data1 and data2 along columns
Step3:
data = data.drop('Unnamed:13', 1) # drop column named 'Unnamed:13'
答案 1 :(得分:0)
只需打开CSV文件作为文本文件,然后将French Cuisine, A Traditional Experience
替换为French Cuisine A Traditional Experience
。
csv_file = open("example.csv", 'r').read()
csv_file = csv_file.replace("French Cuisine, A Traditional Experience", "French Cuisine A Traditional Experience")
open("example.csv", 'w').write(csv_file)