【发布时间】:2019-04-18 13:05:05
【问题描述】:
我有这个数据集。
{
"date": "2018-01-01",
"body": "some txt",
"id": 111,
"sentiment": null
},
{
"date": "2018-01-02",
"body": "some txt",
"id": 112,
"sentiment": {
"basic": "Bearish"
}
}
我想用 pandas 阅读这篇文章,并将每行的列情绪更改为与 null 不同。
当我这样做时:
pd.read_json(path)
这是我得到的结果:
body ... sentiment
0 None
1 {u'basic': u'Bullish'}
我不想拥有{u'basic': u'Bullish'},而只想拥有基本的价值。
所以要找到我使用的正确行
df.loc[self.df['sentiment'].isnull() != True, 'sentiment'] = (?)
它有效,但我不知道我必须放什么来代替 (?)
我试过了,但是不行
df.loc[self.df['sentiment'].isnull() != True, 'sentiment'] = df['sentiment']['basic]
有什么想法吗?谢谢
【问题讨论】: