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

bookGrouping in pandas [1/2]

To perform grouping in pandas, apply the .groupby() method to dataframe, with the column that will determine the groups passed as the parameter.

Note that grouping itself doesn't change the dataframe. Grouping always should come in pair with some aggregation.

For example, our dataframe has the 'morgh' column, representing if the dwelling is mortgaged or not (1 - Yes, 2 - No, 0 - House is being rented). Let's count number of household within each of possible groups (by applying the .size() method).

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').size())
copy

As you can see, 248 people are currently renting a house, while among 771 owners 365 have mortgages.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 2

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

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

Suggested prompts:

Kysy minulta kysymyksiä tästä aiheesta

Tiivistä tämä luku

Näytä käytännön esimerkkejä

Awesome!

Completion rate improved to 2.56

bookGrouping in pandas [1/2]

Pyyhkäise näyttääksesi valikon

To perform grouping in pandas, apply the .groupby() method to dataframe, with the column that will determine the groups passed as the parameter.

Note that grouping itself doesn't change the dataframe. Grouping always should come in pair with some aggregation.

For example, our dataframe has the 'morgh' column, representing if the dwelling is mortgaged or not (1 - Yes, 2 - No, 0 - House is being rented). Let's count number of household within each of possible groups (by applying the .size() method).

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').size())
copy

As you can see, 248 people are currently renting a house, while among 771 owners 365 have mortgages.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 2
some-alt