【问题标题】:Split a pandas column into multiple separate columns depending on number of values [duplicate]根据值的数量将熊猫列拆分为多个单独的列[重复]
【发布时间】:2020-05-08 09:35:54
【问题描述】:

我有一个数据框:

               Values   
                1,2
                nan,7,8
                4
                9,1

如何拆分此列,以便每个值现在都在自己的列中?

               col1       col2     col3 
                1         2
                nan       7          8
                4
                9         1

我找到的唯一答案是将一列分成两列。 How to split a column into two columns?

【问题讨论】:

  • df['Values'].str.split(',',expand=True) ?
  • 如果检查更多答案,还有多列的解决方案

标签: python pandas dataframe


【解决方案1】:

str.splitexpand=True 一起使用:

print(df['Values'].str.split(',', expand=True))

【讨论】:

    猜你喜欢
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2023-01-11
    • 2019-12-28
    • 2019-04-21
    • 1970-01-01
    • 2018-10-17
    相关资源
    最近更新 更多