Note

Pandas (37) 본문

Pandas

Pandas (37)

알 수 없는 사용자 2022. 8. 29. 20:15
728x90

How to get the nrows, ncolumns, datatype, summary stats of each column of a dataframe? Also get the array and list equivalent.

df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv')

#  number of rows and columns
print(df.shape)

# output
(93, 27)

# datatypes
print(df.dtypes)

# output
Manufacturer           object
Model                  object
Type                   object
Min.Price             float64
Price                 float64
Max.Price             float64
MPG.city              float64
MPG.highway           float64
AirBags                object
DriveTrain             object
Cylinders              object
EngineSize            float64
Horsepower            float64
RPM                   float64
Rev.per.mile          float64
Man.trans.avail        object
Fuel.tank.capacity    float64
Passengers            float64
Length                float64
Wheelbase             float64
Width                 float64
Turn.circle           float64
Rear.seat.room        float64
Luggage.room          float64
Weight                float64
Origin                 object
Make                   object
dtype: object

# how many columns under each dtype
print(df.get_dtype_counts())

# output
float64    18
object      9
dtype: int64

print(df.dtypes.value_counts())

# output
float64    18
object      9
dtype: int64

# summary statistics
df_stats = df.describe()

# numpy array 
df_arr = df.values

# list
df_list = df.values.tolist()

'Pandas' 카테고리의 다른 글

Pandas (39)  (0) 2022.08.31
Pandas (38)  (0) 2022.08.30
Pandas (36)  (0) 2022.08.28
Pandas (35)  (0) 2022.08.27
Pandas (34)  (0) 2022.08.26
Comments