Concept Maps of Python Setup
import pandas as pd

# Create example data
data = {
    "Date": [
        "2023-01-01",
        "2023-01-02",
        "2023-01-03",
        "2023-01-04",
        "2023-01-05",
    ],
    "Product": ["A", "B", "A", "C", "B"],
    "Sales": [100, 150, 120, 80, 200],
    "Profit": [30, 40, 25, 10, 50],
}

# Create a DataFrame
df = pd.DataFrame(data)

# Save the DataFrame to a CSV file
df.to_csv("sales_data.csv", index=False)

# Group by Product and calculate total sales and profit
product_group = df.groupby("Product").agg(
    {"Sales": "sum", "Profit": "sum"}
)

# Save the product group to a CSV file
product_group.to_csv("product_group.csv", index=False)

print(
    "Data saved to 'sales_data.csv' and\n"
    "product group data saved to 'product_group.csv'"
)

example_project/01-create_data.py
chendaniely/python_setup
import pandas as pd
import matplotlib.pyplot as plt

# Read product group data from CSV
product_group = pd.read_csv('product_group.csv')

# Bar chart for total sales by product
plt.figure(figsize=(8, 6))  # Set the figure size
product_group['Sales'].plot(kind='bar')
plt.title('Total Sales by Product')
plt.xlabel('Product')
plt.ylabel('Total Sales')
plt.savefig('sales_by_product.png')  # Save the figure as a PNG
plt.show()

example_project/02-viz_pandas.py
chendaniely/python_setup
import pandas as pd
import matplotlib.pyplot as plt

# Scatter plot of Sales vs. Profit
df = pd.read_csv('sales_data.csv')
plt.figure(figsize=(8, 6))  # Set the figure size
plt.scatter(df['Sales'], df['Profit'])
plt.title('Scatter Plot of Sales vs. Profit')
plt.xlabel('Sales')
plt.ylabel('Profit')
plt.savefig('scatter_plot.png')  # Save the figure as a PNG
plt.show()

example_project/03-viz_mpl.py
chendaniely/python_setup