Home > OS >  dictionary inside column of a dataframe
dictionary inside column of a dataframe

Time:04-08

I have a pandas dataframe that has a column like this :

9834    {'id': 5426, 'name': 'Solana', 'symbol': 'SOL'...
9835    {'id': 1839, 'name': 'BNB Smart Chain (BEP20)'...
9836    {'id': 1027, 'name': 'Ethereum', 'symbol': 'ET...
9837    {'id': 1839, 'name': 'BNB Smart Chain (BEP20)'...
9838    {'id': 1027, 'name': 'Ethereum', 'symbol': 'ET...
9839    {'id': 1027, 'name': 'Ethereum', 'symbol': 'ET...
9840    {'id': 1027, 'name': 'Ethereum', 'symbol': 'ET...
9841    {'id': 1839, 'name': 'BNB Smart Chain (BEP20)'...
9842    {'id': 1027, 'name': 'Ethereum', 'symbol': 'ET...
9843    {'id': 1839, 'name': 'BNB Smart Chain (BEP20)'...

I want to make a condition on the whole dataframe based on the id value.

I did many attempts but failed.

only_solana = df[df['platform']['id']==5426]

it says key error, it cannot access 'id' which is inside the column 'platform'.

Any help is welcome, and thank you in advance.

CodePudding user response:

Use Series.str.get and compare in boolean indexing:

only_solana = df[df['platform'].str.get('id')==5426]
  • Related