我有一个数据框,我想把列表提取到另一列中。你知道吗
df = pd.DataFrame({"Q007_A00":["Y","Y","Y","Y","Y"],
"Q007_B00": ["N","N","N","N","N"],
"Q007_C01": [1,4,5,2,"8,3"],
"Q007_C02": ["Text 1","Text 2","Text 3,Text 4,Text 5","Text 4","Text 5,Text 6"]})
Q007_A00 Q007_B00 Q007_C01 Q007_C02
0 Y N 1 Text 1
1 Y N 4 Text 2
2 Y N 5 Text 3,Text 4,Text 5
3 Y N 2 Text 4
4 Y N 8,3 Text 5,Text 6
输出将是
Q007_A00 Q007_B00 Q007_C01 Q007_C01_1 Q007_C02 Q007_C02_1 Q007_C02_2
Y N 1 0 Text 1 0 0
Y N 4 0 Text 2 0 0
Y N 5 0 Text 3 Text 4 Text 5
Y N 2 0 Text 4 0 0
Y N 8 3 Text 5 Text 6 0
列名将加1
可以将^{} 与} 一起使用:
list comprehension
和^{列中的
MultiIndex
可以通过list comprehension
删除:但是如果需要从列名中删除
_0
:相关问题 更多 >
编程相关推荐