Menu
CoddyTech

Inspecting Data

Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 34 of 60.

A new dataset is too long to print. A few quick checks tell you its size, its columns and its values.

A tall table of 24 songs with the columns song, seconds and plays, drawn as a grid; its first 3 rows are highlighted and marked head(3), and a bracket down the side reads 24 rows

songs = pd.read_csv("songs.csv")
print(songs.head(3))   # the first 3 rows; head() alone gives 5
print(songs.shape)     # (rows, columns)
for name in songs.columns:
    print(name)

This prints:

         song  seconds  plays
0   Blue Hour      210   5169
1  Paper Moon      176   6689
2        Tide      272   2739
(24, 3)
song
seconds
plays

.describe() summarizes every number column and leaves out the text column song. print(songs.describe()) prints:

          seconds        plays
count   24.000000    24.000000
mean   212.708333  5116.333333
std     42.367419  2189.610898
min    151.000000  1289.000000
25%    175.250000  3626.250000
50%    213.000000  5051.000000
75%    232.250000  6711.500000
max    290.000000  8992.000000

25%, 50% and 75% are the values a quarter, half and three quarters up the sorted column.

The summary is a table too: "plays" in songs.describe().columns is True, since in asks whether a name is there.

challenge icon

Challenge

Medium

A model learns only from number columns, so a taxi company checks its trip log first. The program loads taxi_trips.csv into trips and reads a number n.

  1. Print Trips: and the number of rows.
  2. For each column, in order, print its name, a colon, and numbers if .describe() summarizes it, else text.
  3. Print the first n rows.

For a table of 30 bike rentals and n = 2:

Trips: 30
bike: text
km: numbers
station: text
   bike    km  station
0  B-12   4.6     Pier
1  B-07  11.2  Central

Try it yourself

import pandas as pd

trips = pd.read_csv("taxi_trips.csv")
n = int(input())

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Plots

Practice on your own: Online Python compiler