Charts and Graphs Data Preparation Prompt

ID: 5636Words in prompt: 107
-
Comments
Unlock the power of insightful data visualization with this expertly crafted prompt template for data preparation. Whether you're an analyst, researcher, or data enthusiast, this versatile template guides you through the meticulous process of refining your data for charts and graphs, paving the way for compelling, data-driven visuals. With this prompt, you can effortlessly tailor it to your unique needs by filling in placeholders with specific data types, manipulation techniques, and visualization tools. It ensures your data is of the highest quality, accuracy, and relevance, guaranteeing that your charts and graphs convey meaningful insights. Elevate your data storytelling, decision-making, and presentations with this professional template. Simply plug in the details and let GPT-3.5 assist you in achieving data visualization excellence.
Created: 2023-11-04
Powered by: ChatGPT Version: 3.5
-/5 (0)Use & rate
Comments (0)

import pandas as pd import matplotlib.pyplot as plt

Load the dataset

data = pd.read_csv("SalesData.csv")

Data preparation Aggregating sales data by month

monthly_sales = data.groupby("Month")["Sales"].sum()

Data cleaning and handling missing values

monthlysales = monthlysales[monthlysales > 0] # Remove negative values monthlysales.fillna(monthly_sales.mean(), inplace=True) # Fill missing values with the monthly average

Data aggregation for quarterly summarization

quarterlysales = monthlysales.resample('Q').sum()

Data labeling

monthlysales.index = monthlysales.index.strftime("%b %Y") # Format month names quarterlysales.index = quarterlysales.index.strftime("Q%q %Y") # Format quarter names

Data scaling (Min-Max scaling)

monthlysales = (monthlysales - monthlysales.min()) / (monthlysales.max() - monthly_sales.min())

Data visualization

plt.figure(figsize=(10, 6)) plt.bar(monthlysales.index, monthlysales.values, label="Monthly Sales") plt.bar(quarterlysales.index, quarterlysales.values, label="Quarterly Sales", alpha=0.5)

Labeling axes

plt.xlabel("Time") plt.ylabel("Total Sales (USD)") plt.xticks(rotation=45) plt.legend() plt.title("Monthly and Quarterly Sales Trends")

Show the bar chart

plt.tight_layout() plt.show()

This code prepares, cleans, and visualizes the sales data using a bar chart, with monthly and quarterly aggregation.