Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

dictionary inside column of a dataframe

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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

only_solana = df[df['platform'].str.get('id')==5426]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading