【问题标题】:How to select the 1st element of the column after splitting?拆分后如何选择列的第一个元素?
【发布时间】:2020-04-23 05:44:01
【问题描述】:

我的 jupyter notebook 中加载了以下与数据科学家职位描述相关的数据框。

这是我从 lambda 表达式得到的输出。

salary = df['Salary Estimate'].apply(lambda x: x.split('(')[0])

如何在不使用 lambda 的情况下获得上述结果?我试过下面的代码

salary = df['Salary Estimate'].str.split('(')[0]

但它给了我以下结果

【问题讨论】:

    标签: python pandas dataframe indexing split


    【解决方案1】:

    使用.str[0] 作为每个列表的第一个值:

    salary = df['Salary Estimate'].str.split('(').str[0]
    

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-20
      • 2018-10-30
      • 2020-08-20
      • 2012-06-29
      • 2011-06-05
      相关资源
      最近更新 更多