Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge | Time Series Data Processing
Data Preprocessing

book
Challenge

Taak

Swipe to start coding

Now, you know how to work with time-series data, and you are faced with the task of processing it:

  1. Convert column data type from str 'Month' to datetime.
  2. Fill NaN values using the interpolation method.
  3. Use the moving average method to remove noise from the data.

Oplossing

import pandas as pd

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

# Convert 'Month' column to datetime format
dataset['Month'] = pd.to_datetime(dataset['Month'], format='%Y-%m')

# Interpolate missing values
dataset['Sunspots'] = dataset['Sunspots'].interpolate(method='linear')

# Remove noise from the data
dataset['Sunspots'] = dataset['Sunspots'].rolling(window=3).mean()

# Print the transformed dataset
print(dataset)

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 6
import pandas as pd

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

# Convert 'Month' column to datetime format
dataset['Month'] = pd.___(dataset['Month'], format=___)

# Interpolate missing values
dataset['Sunspots'] = dataset['Sunspots'].___(method='linear')

# Remove noise from the data
dataset['Sunspots'] = dataset['Sunspots'].___(window=3).mean()

# Print the transformed dataset
print(dataset)
toggle bottom row
some-alt