Tsallaka zuwa abun ciki
Justice Tech School

Shape, Columns and Types

shape gives (rows, columns), columns lists names, dtypes lists types and info prints a summary.

Example
import pandas as pd
import numpy as np
df = pd.DataFrame({'name': ['Ada', 'Bob', 'Cy', 'Di'], 'age': [30, 25, 35, 28], 'city': ['Lagos', 'Accra', 'Lagos', 'Nairobi'], 'score': [88.5, 92.0, 79.5, 85.0]})
print(df.shape)
print(list(df.columns))
print(df.dtypes)
print(len(df))

Result

(4, 4)
['name', 'age', 'city', 'score']
name         str
age        int64
city         str
score    float64
dtype: object
4

Exercise

Get rows and columns.

df.

Quiz Test

What does df.shape return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.