Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge | Feature Engineering
Data Preprocessing

book
Challenge

Aufgabe

Swipe to start coding

Now you can solve a fairly simple task - read a synthetic dataset with profiles on a social network and create new features.

  1. Create a new feature Age Binning (like before) that bins the users' ages into age groups (e.g. 20-30, 30-40, 40-50, etc.). Like, 35 (int) -> 30-40 (str)
  2. Create a second feature Average Hours that counts the average number of hours per week spent on social media by individual users

Lösung

import pandas as pd
import numpy as np

# Read the dataset
dataset = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/9c23bf60-276c-4989-a9d7-3091716b4507/datasets/social_network.csv')

# Age binning
# HINT: use a function pd.cut()
dataset['Age Group'] = pd.cut(dataset['Age'], bins=[10, 20, 30, 40, 50, 60, np.inf], labels=['10-20', '20-30', '30-40', '40-50', '50-60', '60+'])

# Average hours per week
# HINT: use .iloc() method
dataset['Average Hours'] = dataset.iloc[:, 3:-1].mean(axis=1)

# Print the dataset
print(dataset)

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 6
import pandas as pd
import numpy as np

# Read the dataset
dataset = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/9c23bf60-276c-4989-a9d7-3091716b4507/datasets/social_network.csv')

# Age binning
# HINT: use a function pd.cut()
dataset['Age Group'] = pd.___(dataset['Age'], bins=[10, 20, 30, 40, 50, 60, np.inf], ___=['10-20', '20-30', '30-40', '40-50', '50-60', '60+'])

# Average hours per week
# HINT: use .iloc() method
dataset['Average Hours'] = dataset.___[:, 3:-1].___(axis=1)

# Print the dataset
print(dataset)

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt