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
  • 2,023
  • 4
  • 26
  • 53

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
  • 317,841
  • 20
  • 164
  • 234