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
1
  • You would use df[[dic[key1[0]]]]. Commented Feb 24, 2019 at 20:23

1 Answer 1

1

Yes you can but you need

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

df[[dic['key1'][0]]]
     A
0  NaN
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.