Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Grouping in pandas [2/2] | Grouping Data
Data Manipulation using pandas

bookGrouping in pandas [2/2]

As you saw in the previous chapter, you received one number per group. But what will be the result after applying, for example, the .mean() method? Let's find out!

12345678
# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data5.csv') # Grouping and aggregating data print(df.groupby('morgh').mean())
copy

As you can see, you received means for all numerical columns. If you want to get aggregated statistics for only certain columns, make a selection right after applying the .groupby() function. For example, for each value of the 'morth' column we want to know average values of 'valueh', 'grosrth', 'omphtotinch' columns.

12345678
# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data5.csv') # Grouping and aggregating data print(df.groupby('morgh')[['valueh', 'grosrth', 'omphtotinch']].mean())
copy

This time output looks much better. You got means for only selected columns. Zeros as means appeared as the result of house being mortgaged or not.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 2.56

bookGrouping in pandas [2/2]

Pyyhkäise näyttääksesi valikon

As you saw in the previous chapter, you received one number per group. But what will be the result after applying, for example, the .mean() method? Let's find out!

12345678
# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data5.csv') # Grouping and aggregating data print(df.groupby('morgh').mean())
copy

As you can see, you received means for all numerical columns. If you want to get aggregated statistics for only certain columns, make a selection right after applying the .groupby() function. For example, for each value of the 'morth' column we want to know average values of 'valueh', 'grosrth', 'omphtotinch' columns.

12345678
# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data5.csv') # Grouping and aggregating data print(df.groupby('morgh')[['valueh', 'grosrth', 'omphtotinch']].mean())
copy

This time output looks much better. You got means for only selected columns. Zeros as means appeared as the result of house being mortgaged or not.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4
some-alt