Niehra
Niehra

Reputation: 143

Converting row of DataFrame to a Series (Pandas)

So I could not find how to do this in the documentation, but I am reading a row from a dataframe as such:

self.data = df[n:n+1]

But this results in self.data being a 1 row and 7 column dataframe, instead of just a series. However, the test cases for my course depend on it being a series. Is there an easy way to make that conversion?

Upvotes: 1

Views: 106

Answers (1)

chrisaycock
chrisaycock

Reputation: 37930

Just use .ix:

df.ix[n]

That assumes that your df.index lists the rows in numerical order.

Upvotes: 3

Related Questions