Forward fill and backward fill
📖 Scenario: Imagine you have a small table of daily temperatures, but some days are missing values. You want to fill in those missing days by using the last known temperature or the next known temperature.
🎯 Goal: You will create a pandas DataFrame with some missing temperature values. Then, you will add variables to control filling methods. Next, you will apply forward fill and backward fill to fill missing values. Finally, you will print the filled DataFrames.
📋 What You'll Learn
Create a pandas DataFrame called
temps with dates as index and temperature values including NaNCreate a variable called
fill_method to choose between forward fill and backward fillUse the
fillna() method with method=fill_method to fill missing valuesPrint the filled DataFrame
💡 Why This Matters
🌍 Real World
Data often has missing values. Filling missing data helps keep analysis accurate and complete, like filling missing temperature readings in weather data.
💼 Career
Data scientists and analysts frequently clean data by filling missing values to prepare datasets for modeling and reporting.
Progress0 / 4 steps