我有一個像
Tweets Subjectivity Polarity Sentiment
0 This is a sad day. Reversing Roe v. Wade is an... 0.833333 0.000000 Nutral
1 Through renewed investments in malaria and NTD... 0.125000 0.000000 Nutral
2 Daniel Boakye of has spent 45 years working o... 0.317857 0.092857 Positive
3 When most people think about what produces gre... 0.590000 0.173333 Positive
4 The Power by raises timely questions about th... 0.000000 0.000000 Nutral
我想將上面的資料框轉換成每一行的字典陣列,比如
[
{"Tweets" : "tweet1","Subjectivity" : "subjectivity","Polarity":"polarity","Sentiment":"sentiment"},
{"Tweets" : "tweet2","Subjectivity" : "subjectivity","Polarity":"polarity","Sentiment":"sentiment"},
{"Tweets" : "tweet3","Subjectivity" : "subjectivity","Polarity":"polarity","Sentiment":"sentiment"}
...and so on
]
我正在進行情緒分析,并希望將陣列發送到 html 檔案以表格資料的形式列印。為此,我希望將資料框轉換為每行的字典陣列。
uj5u.com熱心網友回復:
使用df.to_dict('records')which 將為您提供行的字典。您可以通過遍歷元素輕松地將字典字典轉換為字典串列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/495781.html
上一篇:選擇器陣列php來刺痛
