【问题标题】:Pandas append string tokens into list with corresponding column where those column in those string rows having same valuePandas 将字符串标记附加到具有相应列的列表中,其中那些字符串行中的列具有相同的值
【发布时间】:2022-11-28 14:06:19
【问题描述】:

所以我正在研究这个dataset

我的问题是如何根据相同的时间戳对这个数据集进行分组并将这些字符串合并为一个独特的代币,所以,例如,我可以:

date string
2011-02-01 15:00:00 Richmond Service Index S&P/CS HPI Composite - 20 s.a. n.s.a Texas Services Sector Outlook TIC Net Long-Term Transactions including Swaps

我不知道应该使用什么方法来解决这个问题。有谁知道如何解决它?

【问题讨论】:

    标签: pandas machine-learning nlp data-science nltk


    【解决方案1】:

    这对你有帮助吗?

    import pandas as pd
    from collections import OrderedDict
    
    df['event'] = df['event'].str.replace('amp;', '')
    df = df.groupby('date')['event'].apply(lambda x: ' '.join(x)).reset_index()
    df['event'] = df['event'].str.split().apply(lambda x: OrderedDict.fromkeys(x).keys()).str.join(' ')
    

    【讨论】:

      猜你喜欢
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      • 2019-03-20
      相关资源
      最近更新 更多