在使用Pandas的时候,有时候某些列里面存储的是字典,我们需要将这个字典里面的提出出来处理。使用apply
函数即可。
例如videos_df
是一个DataFrame
对象,它的statistics
列是一个字典列,如图所示
具体格式为
{'aweme_id': '7067130856871038221',
'comment_count': 6,
'digg_count': 115,
'forward_count': 0,
'play_count': 0,
'share_count': 5
}
使用apply
函数后,即可得到该字典列分解后得到的DataFrame
对象
statistics = videos_df["statistics"].apply(pd.Series)
得到的结果如图所示