繁体   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