How to check a numpy / pandas object i.e. Str () in R

When I use R, I can use str()to check objects, which are a list of things in most cases.

I recently switched to Python for statistics and don’t know how to check the objects that I encounter. For example:

import statsmodels.api as sm
heart = sm.datasets.heart.load_pandas().data
heart.groupby(['censors'])['age']

I want to find out what kind of object heart.groupby(['censors'])that allows me to add ['age']to the end. However print heart.groupby(['censors']), the type of object tells me, not its structure and what I can do with it.

So, how do I understand the structure of a numpy / pandas object similar str()in R?

+1
source share
3 answers

, Python, Python, IPython. IPython , , :

import statsmodels.api as sm
heart = sm.datasets.heart.load_pandas().data
h_grouped = heart.groupby(['censors'])

Tab, :

In [5]: h_grouped.<Tab><Tab>
# Shows the object methods

IPython - help , ?:

h_grouped.apply?
# Apply function and combine results 
# together in an intelligent way.

IPython , - , dir(), . dir(h_grouped), , .

+1
type(heart.groupby(['censors'])['age'])

type , . pandas, age. , , :

heart.groupby(['censors'])['age'].mean()

.

0

groupby I think the red herring - "age" - is just the name of the column:

import statsmodels.api as sm

heart = sm.datasets.heart.load_pandas().data
heart
#      survival  censors   age
#  0         15        1  54.3
#  ...

heart.keys()
#  Index([u'survival', u'censors', u'age'], dtype='object')
0
source

Source: https://habr.com/ru/post/1615856/


All Articles