【发布时间】:2018-04-29 13:32:11
【问题描述】:
我有一个这样的数据框:
index S_1 S_2 S_3 S_4
0 1 0 0 1
1 1 1 Nan Nan
我正在尝试将其从长更改为宽。例如。
index num S
0 1 1
0 2 0
0 3 0
0 4 1
1 1 1
1 2 1
1 3 Nan
1 4 Nan
我根据this 的回答尝试了以下代码,但出现以下错误:
matches_df.columns = matches_df.columns.str.split('_', expand=True)
TypeError: 'float' 类型的对象没有 len()
为什么我无法在“_”上拆分?我想保留列中的其他信息。
【问题讨论】: