Get particular row as series from pandas dataframe

Posted by Pratyush on Stack Overflow See other posts from Stack Overflow or by Pratyush
Published on 2013-10-25T21:18:07Z Indexed on 2013/10/25 21:54 UTC
Read the original article Hit count: 229

Filed under:
|

How do we get a particular filtered row as series?

Example dataframe:

>>> df = pd.DataFrame({'date': [20130101, 20130101, 20130102], 'location': ['a', 'a', 'c']})
>>> df
       date location
0  20130101        a
1  20130101        a
2  20130102        c

I need to select the row where location is c as a series.

I tried:

row = df[df["location"] == "c"].head(1)  # gives a dataframe
row = df.ix[df["location"] == "c"]       # also gives a dataframe with single row

In either cases I can't the row as series.

© Stack Overflow or respective owner

Related posts about python

Related posts about pandas