我正在嘗試下載此測驗 json 檔案以在分類專案中使用它。我使用以下代碼將此 JSON 檔案轉換為 Pandas 中的 csv 檔案:
test_sarcasm_df = pd.read_json('/content/drive/My Drive/Sarcasm Data/test_sarcasm.json')
我在 ML 專案中使用它,但它的格式錯誤。我不熟悉 JSON 及其大檔案,所以有什么方法可以格式化它,使第一列成為資料框中的第一行?
我很感激你們能給我的任何幫助!
這是資料框的樣子:

uj5u.com熱心網友回復:
Pandas transpose 正好解決了這個問題:
from pandas import DataFrame
df = DataFrame([{"row1": "text2", "row2": "text1"},{"row1": "bob", "row2": "james"}])
df.index = ["text", "author"]
print(df.head(2))
# this is essentially the starting position
row1 row2
text text2 text1
author bob james
# now we transpose
df = df.transpose()
print(df.head(2))
# problem solved :)
text author
row1 text2 bob
row2 text1 james
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/368363.html
上一篇:將一串數字變成對應的字母
