0

I have a pandas dataframe that consists of multiple series. I want to get one series by name, but for the life of me can't figure out how to do it.

Dataframe:

         user_id  name    
gender                                                       
male       1      John 
female     2     Abigal

I want to get the name of the male series. Something like df['male'].name

Thank you!

Matt
  • 478
  • 4
  • 14
  • You should probably read [10 min to pandas](https://pandas.pydata.org/pandas-docs/stable/user_guide/10min.html). `.loc` is fairly fundamental. – noah Jan 15 '21 at 19:48

1 Answers1

2

Simply use .loc:

df.loc['male','name']
noah
  • 2,616
  • 13
  • 27
  • That works, I was circling the answer, thank you!! Can I default to 0 is the series with that name doesn't exist? – Matt Jan 15 '21 at 19:51
  • see https://stackoverflow.com/questions/23403352/return-default-if-pandas-dataframe-loc-location-doesnt-exist – noah Jan 15 '21 at 19:52