1

I have a dataframe, df with columns headers A, B , C, D

can I reference these headers from this dictionary?

dic={'key1':['A','B'],
key2: [C,D]}

df[key1[0]]

giving the output of just column A?

   A
0  44
1  44
2  44
3  33
fred.schwartz
  • 1,879
  • 20
  • 41

1 Answers1

1

Yes you can but you need

df[dic['key1']]
     A    B
0  NaN  NaN

df[[dic['key1'][0]]]
     A
0  NaN
BENY
  • 296,997
  • 19
  • 147
  • 204