'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.
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 1:[1]
Use Series.str.get and compare in boolean indexing:
only_solana = df[df['platform'].str.get('id')==5426]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
