繁体   English   中英

从熊猫列中的列表中列出字典

[英]Listed dictionaries from list inside a pandas column

我有这样的数据

{'message_text': '*प्रशासक समिति*',
'translated_text': '* Administrator ',
'annotation_list': ['Fear speech', 'Fear speech', 'Normal'],
'propagation': [{'group_id': 9087,
'user_id': 229869,
'timestamp': 1538130086000},
{'group_id': 7, 'user_id': 215, 'timestamp': 1550186113000}]}


current code
df=pd.DataFrame.from_dict(fear_speech_data, orient='index')

目前,我只能阅读四列的代码

message_text    
translated_text 
annotation_list 
propagation

我想将上述详细信息读入数据框中,其中包含数据框中的以下列

message_text    
translated_text 
annotation_list 
propagation
group_id
user_id
timestamp
group_id
user_id
timestamp

基于数据链更新

我从提供的 json 中取出了值,因为它不容易使用,但我认为这是你想要的

from flatten_json import flatten
url ='https://raw.githubusercontent.com/hate-alert/Fear-speech-analysis/master/Data/fear_speech_data.json'
r = requests.get(url)
data = json.loads(r.text)

#list(data.values())
    
dic_flattened = (flatten(d, '.') for d in list(data.values()))
df = pd.DataFrame(dic_flattened)

输出

                                           message_text                                    translated_text annotation_list.0 annotation_list.1  ... propagation.241.group_id  propagation.241.user_id  propagation.241.timestamp  propagation
0     *प्रशासक समिति*✊🚩  ●●●●●●●●●●● ● ● ● 😎🚩 *आंतकव...  * Administrator ✊ 🚩   Committee * ● ●●●●●●●●●●...       Fear speech       Fear speech  ...                      NaN                      NaN                        NaN          NaN
1     हैदराबाद की मक्का मस्जिद में ब्लास्ट 16 मरे 10...  Blast 16 killed and 100 injured in Hyderabad's...            Normal            Normal  ...                      NaN                      NaN                        NaN          NaN
2     *(1) - "इस्लाम धर्म नहीं एक मानसिक रोग है" - श...  * (1) - "Islam is not a religion but a mental ...       Fear speech       Fear speech  ...                      NaN                      NaN                        NaN          NaN
3     पाकिस्तान से अधिक तो जमात-ए-इस्लामी के संसाधन ...  Jamaat-e-Islami has more resources than Pakist...       Fear speech            Normal  ...                      NaN                      NaN                        NaN          NaN
4     शहरी नक्सलवाद माओवाद । बस एक निवेदन ... पढ़ना ...  Urban Naxalism Maoism. Just a request… start r...            Normal            Normal  ...                      NaN                      NaN                        NaN          NaN
...                                                 ...                                                ...               ...               ...  ...                      ...                      ...                        ...          ...
4777  हिन्दुओं से बेशर्म कोई जाति पूरा पढ़े कठोर वचन...  I also apologize to the Hindus for the shamele...       Fear speech            Normal  ...                      NaN                      NaN                        NaN          NaN
4778  अब भी नही जागे तो मधेपुरा पूर्णिया में भी हिंद...  Even if you do not wake up, then in Madhepura ...       Fear speech       Fear speech  ...                      NaN                      NaN                        NaN          NaN
4779  इतिहास का सबसे बड़ा छल हिंदुओं के साथ हुआ  मुस...  The biggest trick of history happened to Hindu...            Normal            Normal  ...                      NaN                      NaN                        NaN           []
4780  फिर कहते हैं #राममन्दिर नहीं बना _____________...  Then it says #Ramandir is not made ___________...       Fear speech       Fear speech  ...                      NaN                      NaN                        NaN          NaN
4781  *उर्दू हिन्दुस्तान के देशभक्त क्रांतिकारियों क...  * Urdu is the tongue of the patriotic revoluti...            Normal            Normal  ...                      NaN                      NaN                        NaN          NaN

[4782 rows x 732 columns]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM