【发布时间】:2016-09-28 13:06:56
【问题描述】:
我收到了一个 csv,其中的一列数据是一个 json 字符串,加载到 pandas 中时如下所示:
df.registered_office.head()
3 {u"country": u"United Kingdom", u"region": None, u"postal_code": u"ST6 3HL", u"street_address": u"Martin Leake House Waterloo Road\nCobridge", u"locality": u"Stoke On Trent"}
5 {u"country": u"England", u"region": None, u"postal_code": u"BS32 4JY", u"street_address": u"Woodlands Grange Woodlands Lane\nBradley Stoke", u"locality": u"Bristol"}
7 {u"country": u"United Kingdom", u"region": u"Staffordshire", u"postal_code": u"ST6 8JD", u"street_address": u"136 Knypersley Road\nNorton", u"locality": u"Stoke On Trent"}
8 {u"country": u"United Kingdom", u"region": u"Staffordshire", u"postal_code": u"ST9 9HQ", u"street_address": u"Ashlands\n253 Leek Road, Endon", u"locality": u"Stoke On Trent"}
9 {u"country": u"United Kingdom", u"region": None, u"postal_code": u"ST1 5TA", u"street_address": u"C/O Kpmg Festival Way\nStoke On Trent", u"locality": None}
Name: registered_address, dtype: object
根据各种键将此列转换为新数据框或新列的最 Pythonic 方式是什么?
【问题讨论】: