I have a pkl file that when i open it up using pd.read_pickle the data is shown as a list, example below:
[{'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},
I really want to use the specific dataset to conduct a sentiment analysis but i honestly dont know how to convert the pkl file into a dataframe, were the columns are text and label and show the text with the corresponding label on each row.
I suspect the pkl file is not originally generated using DataFrame.to_pickle so it cannot be unpicked into a data frame using pd.read_pickle.
How I would do it, is to put the list into a pandas DataFrame using from_records , for example:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.