Galaxy S
Galaxy S

Reputation: 39

Pandas: How to extract value from a row from describe() into a variable?

enter image description here

So if i wanted to get the count and store it as a variable z. I know I can do something like df.describe().loc['count'] but i am unable to extract the number to variable z itself to do mathematical operations like addition.

Upvotes: 1

Views: 641

Answers (1)

Laurent
Laurent

Reputation: 13518

Pandas describe method returns a Series or a DataFrame.

So, you can extract and assign any specific value like this (although it is easier to use the corresponding method, as suggested by @tdy):

z = df.describe().loc["50%"].tolist()[0]

print(type(z))  # <class 'float'>

Upvotes: 1

Related Questions