簡體   English   中英

將 pkl 文件轉換為列而不是列表

[英]convert pkl file into columns rather than a list

我有一個 pkl 文件,當我使用 pd.read_pickle 打開它時,數據顯示為列表,示例如下:

[{'text': 'what is your favorite song ? d i like too many songs to have a favorite',
  'label': 0},
 {'text': '3 3 ? haha jk ! 33', 'label': 0},
 {'text': 'hey angel you duh sexy really ? ! ? ! thanks ? ! haha', 'label': 0},
 {'text': '', 'label': 0},
 {'text': 'meowww rawr ?', 'label': 0},

我真的很想使用特定的數據集進行情緒分析,但老實說,我不知道如何將 pkl 文件轉換為 dataframe,列是文本和 label 並在每行顯示帶有相應 ZD304BA20E96D87434Z8158 的文本。

我懷疑 pkl 文件最初不是使用DataFrame.to_pickle生成的,因此無法使用 pd.read_pickle 將其解壓縮到數據框中。

我會怎么做,是使用from_records將列表放入 pandas DataFrame 中,例如:

import pandas as pd
user_data=[{'text': 'what is your favorite song ? d i like too many songs to have a favorite',
  'label': 0},
 {'text': '3 3 ? haha jk ! 33', 'label': 0},
 {'text': 'hey angel you duh sexy really ? ! ? ! thanks ? ! haha', 'label': 0},
 {'text': '', 'label': 0},
 {'text': 'meowww rawr ?', 'label': 0},]
user_df = pd.DataFrame.from_records(data=user_data)

暫無
暫無

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

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