Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 拆分列表并转换为熊猫中的数据帧_Python 3.x_Pandas_List - Fatal编程技术网

Python 3.x 拆分列表并转换为熊猫中的数据帧

Python 3.x 拆分列表并转换为熊猫中的数据帧,python-3.x,pandas,list,Python 3.x,Pandas,List,给出如下列表: ['start year: 2019', 'end year: 2021'] 我如何将它们拆分为:并转换为数据帧 start year end year 2019 2021 提前感谢您的帮助。您可以这样做 df = pd.DataFrame([x.split(':')for x in l ]).set_index(0).T 0 start year end year 1 2019 2021 你能行 df = pd.Da

给出如下列表:

['start year: 2019', 'end year: 2021']
我如何将它们拆分为:并转换为数据帧

start year      end year
  2019            2021
提前感谢您的帮助。

您可以这样做

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

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

我可以问一下:为什么列名行是0,索引0应该从2019 2021行开始,对吗?我可以问一下:为什么列名行是0,索引0应该从2019 2021行开始,对吗?