Melt for wide-to-long reshaping
📖 Scenario: You work in a small company that tracks monthly sales for different products. The sales data is stored in a table where each product has its own column for each month. This format is hard to analyze because the months are spread across columns.To make the data easier to analyze, you want to reshape it from wide format (many columns for months) to long format (one column for month and one for sales).
🎯 Goal: Learn how to use the pandas.melt() function to reshape a wide table into a long table. You will start with a dictionary of sales data, convert it to a DataFrame, then reshape it so each row shows a product, month, and sales value.
📋 What You'll Learn
Create a pandas DataFrame from a dictionary with product sales for three months
Define the columns to keep fixed during reshaping
Use pandas melt to reshape the DataFrame from wide to long format
Print the reshaped DataFrame
💡 Why This Matters
🌍 Real World
Data scientists often receive data in wide format, which is hard to analyze. Reshaping data to long format helps in plotting, grouping, and applying statistical methods.
💼 Career
Knowing how to reshape data with pandas melt is a key skill for data cleaning and preparation, essential for roles like data analyst, data scientist, and business intelligence specialist.
Progress0 / 4 steps