【问题标题】:Extract last part of the string pandas提取字符串 pandas 的最后一部分
【发布时间】:2022-09-24 00:07:50
【问题描述】:

我有一列包含值:

虚拟数据:

df[\"temp_design\"] = [\'Are Premium Design tree (LKL#)\',
       \'THE Premium Design tree (TKL+)\',
       \'THZPremium Design tree (TKL+)\',
       \'THG THEM Entry tree temporary align (MKP#)\', nan,
       \'THZPremium Design tree (CHU#)\',
       \'THZPremium Design tree (ZHU2+)\',
       \'TRUE PREMIUM TEMPORARY DESIGN (ZHU+)\',
       \'BASIC TEMPORARY DESIGN (ZHU+)\']

我想创建一个新列,其值存在于最后一个括号内。

谁能帮我去掉这个字符串?

df[\"output_col\"] =[\"LKL#\",\"TKL+\",\"TKL+\",\"MKP#\",\"CHU#\",\"ZHU2+\",\"ZHU+\",\"ZHU+\"]

    标签: python pandas dataframe


    【解决方案1】:
    df['temp_design'].str.extract(r'\((.*?)\)') 
    
        0
    0   LKL#
    1   TKL+
    2   TKL+
    3   MKP#
    4   NaN
    5   CHU#
    6   ZHU2+
    7   ZHU+
    8   ZHU+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 2019-03-21
      • 2020-12-18
      相关资源
      最近更新 更多