0

これはjsonlの私のデータ構造です

"content": "Not yall gassing up a gay boy with no rhythm", "place": {"_type": "snscrape.modules.twitter.Place", "fullName": "Manhattan, NY", "name": "Manhattan", "type": "city", "country": "United States", "countryCode": "US"}

このコードで場所の列からcountryCodeを選択しようとしています

country_df = test_df.loc[test_df['place'].notnull(), ['content', 'place']]
countrycode_df = country_df["place"].loc["countryCode"]

しかし、それは私にこのエラーを与えました

KeyError: 'countryCode'

どうすればこれを修正できますか?

この方法を試してみましたが、私の状況には合いませんでした

4

2 に答える 2

1

次の方法でアクセスできますstr

country_df['place'].str['countryCode']

出力:

0    US
Name: place, dtype: object
于 2021-05-29T14:17:13.963 に答える