Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Number of Observations | Aggregate Functions
Introduction to pandas [track]
course content

Kursinnhold

Introduction to pandas [track]

Introduction to pandas [track]

1. Basics
2. Reading and Exploring Data
3. Accessing DataFrame Values
4. Aggregate Functions

book
Number of Observations

There are several aggregate functions in pandas. One of them is .count() method, which counts number of non-null observation for each column.

1234567
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Count number of non-null rows print(df.count())
copy

This method is popular for counting number of rows under specific condition. For example, you may count number of cars manufactured after 2015. This time you don't need to see the number of observation in each column, so you can choose particular one.

1234567
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Count number of cars manufactured after 2015 print(df.loc[df.year > 2015, 'model'].count())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 1

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to pandas [track]

Introduction to pandas [track]

1. Basics
2. Reading and Exploring Data
3. Accessing DataFrame Values
4. Aggregate Functions

book
Number of Observations

There are several aggregate functions in pandas. One of them is .count() method, which counts number of non-null observation for each column.

1234567
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Count number of non-null rows print(df.count())
copy

This method is popular for counting number of rows under specific condition. For example, you may count number of cars manufactured after 2015. This time you don't need to see the number of observation in each column, so you can choose particular one.

1234567
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Count number of cars manufactured after 2015 print(df.loc[df.year > 2015, 'model'].count())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 1
Vi beklager at noe gikk galt. Hva skjedde?
some-alt