【发布时间】:2023-01-18 02:36:23
【问题描述】:
我需要你的帮助来完成以下任务: 我有以下数据框:
test = {'Col1':[2,5],
'Col2':[5,7],
'Col_List':[['One','Two','Three','Four','Five'], ['Two', 'Four']],
'One':[0,0],
'Two':[0,0],
'Three':[0,0],
'Four':[0,0],
'Five':[0,0],}
df=pd.DataFrame.from_dict(test)
df
看起来像:
| Col1 | Col2 | Col_List | One | Two | Three | Four | Five |
|---|---|---|---|---|---|---|---|
| 2 | 5 | [One, Two, Three, Four, Five] | 0 | 0 | 0 | 0 | 0 |
| 5 | 7 | [Two, Four] | 0 | 0 | 0 | 0 | 0 |
我需要检查 Col_List 中的列表,并根据列表中的项目设置特定列中 Col1 列的值(One、Two、Three、Four 或Five)。
现在我想得到以下结果:
| Col1 | Col2 | Col_List | One | Two | Three | Four | Five |
|---|---|---|---|---|---|---|---|
| 2 | 5 | [One, Two, Three, Four, Five] | 2 | 2 | 2 | 2 | 2 |
| 5 | 7 | [Two, Four] | 0 | 5 | 0 | 5 | 0 |
【问题讨论】:
标签: python pandas list dataframe