代码之家  ›  专栏  ›  技术社区  ›  Bilal Butt

如何从json文件中获取不同或唯一的字符串行

  •  0
  • Bilal Butt  · 技术社区  · 7 年前

    我有推特的json文件,其中包含以下数据。

    ID、全名、文本、时间戳、URL用户、全名、转发等

    每个json文件都是唯一的,但在某些json中,['TEXT']字段是相同的。

    我想删除那些在['text']字段中包含相同推文的json文件。

    下面是我的json文件示例。。两个json都来自不同的用户,但他们推特的文本相同。

        {
      'fullname': 'آدم',
      'id': '772154564711768064',
      'likes': '5',
      'replies': '0',
      'retweets': '0',
      'text': '#GoNawazGoNawaz\n''This woman has realized the truth....hope nation realizes it ''too.... \n''#PanamaLeaks\n''#GoNawazGoNawazpic.twitter.com/6m7nWgldQp',
      'timestamp': '2016-09-03T19:29:28',
      'url': '/NaikOlad/status/772154564711768064',
      'user': 'NaikOlad'
    }{
      'fullname': 'سلمان اعوان',
      'id': '772156567542231040',
      'likes': '0',
      'replies': '0',
      'retweets': '0',
      'text': '#GoNawazGoNawaz\n''This woman has realized the truth....hope nation realizes it ''too.... \n''#PanamaLeaks\n''#GoNawazGoNawazpic.twitter.com/L2tZUOVs1z',
      'timestamp': '2016-09-03T19:37:26',
      'url': '/SaluBhai420/status/772156567542231040',
      'user': 'SaluBhai420'
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   YakovL Naresh Kumar Nakka    7 年前
    import pandas as pd
    df1 = pd.Dataframe()
    df1 = df1.append(first_tweet_json,ignore_index=True)
    df1 = df1.append(second_tweet_json,ignore_index=True)
    df1 = df1.drop_duplicates(subset=['text'],keep='last')
    print(df1)