Python. Get structure from a data.frame

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.


The functions below may help you find the data types of a DF.

DF.info


DF.dtypes

OP:
ltv                                    float64
branch_id                                int64
supplier_id                              int64
manufacturer_id                          int64
Current_pincode_ID                       int64
Date.of.Birth                           object

If you are looking for an equivalent of Rs data.frame, you will want to look into pandas.

The pandas.DataFrame might be what you are looking for.

The get an idea of what is in a DataFrame you could use the .describe or .head methods.

import pandas as pd

data = pd.DataFrame({
    'a': [1, 2, 3, 4, 5],
    'b': [1, 2, 3, 4, 5]
})

print(data.head())
print(data.describe())
print(data.columns)

Or, which might be a little to verbose, just:

print(data)

Tags:

Python

Pandas

R