【发布时间】:2020-05-25 23:37:40
【问题描述】:
我还是 python 新手,你能帮我解决这个问题吗
i have this excel sheet
and i want it to be like this
【问题讨论】:
-
这里有一个帖子可以参考:stackoverflow.com/questions/36271413/…
我还是 python 新手,你能帮我解决这个问题吗
i have this excel sheet
and i want it to be like this
【问题讨论】:
您可以像这样将 csv 数据转换为 panda 数据框:
import pandas as pd
df = pd.read_csv("Input.csv")
然后像这样进行数据操作:
df = df.groupby(['Name'])['Training'].apply(', '.join).reset_index()
最后,创建一个输出 csv 文件:
df.to_csv('Output.csv', sep='\t')
【讨论】:
您可以使用pandas 创建DataFrame 来操作Excel 工作表信息。首先,使用函数read_excel 加载文件(这将创建一个DataFrame),然后使用函数groupby 和apply 连接字符串。
import pandas as pd
# Read the Excel File
df = pd.read_excel('tmp.xlsx')
# Group by the column(s) that you need.
# Finally, use the apply function to arrange the data
df.groupby(['Name'])['Training'].apply(','.join).reset_index( )
【讨论】: