I have a huge pandas dataframe 150000 x 330 and I well find columns that have lists []
I have tried
JavaScript
x
2
1
df[['[]' in x for x in df.values]]
2
but it only returns column names.
JavaScript
1
15
15
1
df['FORM_SECTION.CONTRACT.FD_CONTRACT.CONTRACTING_AUTHORITY_INFORMATION.NAME_ADDRESSES_CONTACT_CONTRACT.SPECIFICATIONS_AND_ADDITIONAL_DOCUMENTS.CONTACT_DATA.E_MAILS.E_MAIL']
2
3
0 [dsfd@inventura.no]
4
1 [---@sivingtt.no]
5
2 None
6
3 None
7
4 None
8
9
152463 None
10
152464 None
11
152465 None
12
152466 None
13
152467 None
14
Name: FORM_SECTION.CONTRACT.FD_CONTRACT.CONTRACTING_AUTHORITY_INFORMATION.NAME_ADDRESSES_CONTACT_CONTRACT.SPECIFICATIONS_AND_ADDITIONAL_DOCUMENTS.CONTACT_DATA.E_MAILS.E_MAIL, Length: 152468, dtype: object
15
Advertisement
Answer
You can try:
JavaScript
1
2
1
df.applymap(lambda x: isinstance(x, list)).any()
2
Demo
JavaScript
1
17
17
1
data = {'Col1': [0, 1, 2], 'Col2': [['a', 'b'], ['a'], ['c']], 'Col3': [1.1, 2.2, 3.3]}
2
df = pd.DataFrame(data)
3
4
print(df)
5
6
Col1 Col2 Col3
7
0 0 [a, b] 1.1
8
1 1 [a] 2.2
9
2 2 [c] 3.3
10
11
df.applymap(lambda x: isinstance(x, list)).any()
12
13
Col1 False
14
Col2 True
15
Col3 False
16
dtype: bool
17
You can also find the list of columns with list as follows:
JavaScript
1
2
1
df.columns[df.applymap(lambda x: isinstance(x, list)).any()].tolist()
2
Output:
JavaScript
1
2
1
['Col2']
2