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

Kursusindhold

Introduction to pandas [track]

Introduction to pandas [track]

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

book
Sum and Product

To calculate the total sum and product you can use the .sum() and .prod() methods, respectively. These methods can be applied to an entire DataFrame; in that case, the corresponding operation will be performed for each column. For instance, we can calculate the total price of all cars manufactured in 2010.

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') # Total price of 2010 cars print(df.loc[df.year == 2010, 'price'].sum())
copy

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 5

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

course content

Kursusindhold

Introduction to pandas [track]

Introduction to pandas [track]

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

book
Sum and Product

To calculate the total sum and product you can use the .sum() and .prod() methods, respectively. These methods can be applied to an entire DataFrame; in that case, the corresponding operation will be performed for each column. For instance, we can calculate the total price of all cars manufactured in 2010.

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') # Total price of 2010 cars print(df.loc[df.year == 2010, 'price'].sum())
copy

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 5
Vi beklager, at noget gik galt. Hvad skete der?
some-alt