簡體   English   中英

將JSON文件讀入pandas數據框

[英]Read a JSON file into a pandas dataframe

我正在嘗試讀取一系列JSON文件並將其轉換為Pandas DataFrame,但是,我所遵循的所有示例都不適用於閱讀部分。

這是我擁有的JSON文件的示例:

{
    "created_at": "Thu Nov 02 01:09:12 +0000 2017",
    "text": "RT @coindesk: SEC: Celebrity ICO Endorsements Could Be Illegal gHoWduXOBp t.co/iyWla0Ryuk",
    "tweet_id": 925892516087558145,
    "user_id": 153962533,
    "user_name": "Christine Duhaime"
}{
    "created_at": "Thu Nov 02 01:09:44 +0000 2017",
    "text": "Cornell Professor C t.co/RuNu6UQyr9",
    "tweet_id": 925892650884108289,
    "user_id": 1255045351,
    "user_name": "Local SEO Somerset"
}

我試過了:

with codecs.open('./output/streamer_20171022-2010.json', 'r+', encoding='utf-8') as data_file:
    data = json.load(data_file)

導致

JSONDecodeError: Extra data: line 1 column 416 (char 415)

我也嘗試逐行閱讀...沒有成功。

任何想法?

您的JSON文件格式無效。 有效JSON中只能有一個頂級元素

嘗試將頂級對象放置到數組中。

[
    { "created_at": "Thu Nov 02 01:09:12 +0000 2017", 
      "text": "RT @coindesk: SEC: Celebrity ICO Endorsements Could Be Illegal gHoWduXOBp t.co/iyWla0Ryuk",
      "tweet_id": 925892516087558145,
      "user_id": 153962533, 
      "user_name": "Christine Duhaime" 
    }, { 
      "created_at": "Thu Nov 02 01:09:44 +0000 2017",
      "text": "Cornell Professor C t.co/RuNu6UQyr9", 
      "tweet_id": 925892650884108289,
      "user_id": 1255045351,
      "user_name": "Local SEO Somerset" 
    }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM