Example dataframe:
class fred bill
0 a 23 35
1 b 123 45
2 c 34 45
3 d 4 45
(pandas adds the index (0->3) which isn't needed)
What i want is to say something like:
fred_b_class = df.at['fred','b']
>>> 123
I tried setting the column 'class' as the index by pd.set_index('class')
However when calling df.index.name it returned none
I think you need set_index from column class and then swap arguments in at, because first argument is index and second column name:
df = df.set_index('class')
#df.set_index('class', inplace=True)
print (df)
fred bill
class
a 23 35
b 123 45
c 34 45
d 4 45
print (df.at['b','fred'] )
123
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With