在熊猫中拆分列表并转换为数据框

时间:2020-07-07 02:49:07

标签: python-3.x pandas list

给出如下列表:

['start year: 2019', 'end year: 2021']

如何将它们:分割并转换为数据框?

start year      end year
  2019            2021

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

你可以做

df = pd.DataFrame([x.split(':')for x in l ]).set_index(0).T
0 start year end year
1       2019     2021