Pandas分裂dataframe

来源:互联网 发布:android和java区别 编辑:程序博客网 时间:2024/05/16 05:07
In [3]: df = pd.DataFrame({'years': ['1900-2000', '1920-2020', '1930-2030']})In [4]: dfOut[4]:       years0  1900-20001  1920-20202  1930-2030In [14]: df['start'], df['end'] = zip(*df['years'].map(lambda x: x.split('-')))In [15]: dfOut[15]:       years start   end0  1900-2000  1900  20001  1920-2020  1920  20202  1930-2030  1930  2030

[1].https://www.reddit.com/r/learnpython/comments/44ktvo/help_splitting_a_pandas_dataframe_column_into_two/?st=ja23b97o&sh=c8fffd95
[2].https://stackoverflow.com/questions/17116814/pandas-how-do-i-split-text-in-a-column-into-multiple-rows

原创粉丝点击