Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python. Get structure from a data.frame

Tags:

python

pandas

r

In r, with the str() function you can see structure from an object like this:

> str(mari)
'data.frame':   25834 obs. of  6 variables:
 $ Xcoor: num  0.0457 0.0469 0.0481 0.0495 0.0519 ...
 $ Ycoor: num  0.107 0.107 0.107 0.108 0.108 ...
 $ Zcoor: num  -0.701 -0.701 -0.701 -0.703 -0.703 ...
 $ RC   : int  120 124 124 125 124 122 120 120 120 120 ...
 $ GC   : int  121 117 117 117 118 119 120 120 120 120 ...
 $ BC   : int  127 135 144 135 126 127 125 125 124 137 ...

Is there a similar function like this one?

like image 220
Jose Avatar asked Apr 07 '16 16:04

Jose


People also ask

How do you find the structure of a DataFrame in Python?

In r, with the str() function you can see structure from an object like this: > str(mari) 'data. frame': 25834 obs. of 6 variables: $ Xcoor: num 0.0457 0.0469 0.0481 0.0495 0.0519 ...

What function should be used to get the structure of the data frame?

Get the Structure of the Data Frame The structure of the data frame can be seen by using str() function.


1 Answers

I realize this is an old question, but wanted to provide clarification for anyone else that comes across this question in the future like I did.

As MaxNoe said, pandas is what is needed and the pandas.DataFrame.info method is the equivalent to the str() function in R.

Using the same example as MaxNoe:

>>> import pandas as pd
>>> data = pd.DataFrame({
    'a': [1, 2, 3, 4, 5],
    'b': [1, 2, 3, 4, 5]
})
>>> data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 2 columns):
a    5 non-null int64
b    5 non-null int64
dtypes: int64(2)
memory usage: 160.0 bytes

The documentation can be found here https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.info.html.

like image 195
Alex B Avatar answered Oct 08 '22 19:10

Alex B