python dataframe columns is a list drop

Solutions on MaxInterview for python dataframe columns is a list drop by the best coders in the world

showing results for - "python dataframe columns is a list drop"
Damián
02 Jul 2018
1# Df with a coulmn (dims) that contain list
2key1 = 'site channel fiscal_week'.split()
3key2 = 'site dude fiscal_week'.split()
4key3 = 'site eng fiscal_week'.split()
5
6keys = pd.DataFrame({'key': [1,2,3],
7                     'dims': [key1,key2,key3]})
8
9# Output
10                         dims  key
11[site, channel, fiscal_week]    1
12[site, dude, fiscal_week]       2
13[site, eng, fiscal_week]        3
14
15
16# Solution
17keys['reduced_dims'] = keys['dims'].apply(
18    lambda row: [val for val in row if val != 'fiscal_week']
19)
20
similar questions
queries leading to this page
python dataframe columns is a list drop