【问题标题】:Removing inverted commas and brackets from python dataframe column items从 python 数据框列项中删除引号和括号
【发布时间】:2022-12-23 16:18:19
【问题描述】:

df1

         Place                             Actor
['new york','washington']         ['chris evans','John']    
['new york','los angeles']        ['kate','lopez']

我想从每列项目中删除括号和引号:

预期输出:

df1

         Place                 Actor
new york,washington        chris evans,John   
new york,los angeles       kate,lopez

我的尝试:

cols = [Place,Actor]
df1[cols].apply(lambda x : x [' + ', '.join(df1[cols]) + ']')
   

【问题讨论】:

    标签: python pandas string text split


    【解决方案1】:

    使用Series.str.join:

    cols = ['Place','Actor']
    df1[cols] = df1[cols].apply(lambda x : x.str.join(', '))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      相关资源
      最近更新 更多