scatter missing vendor

scatter missing vendor

To plot the median observations for each month and vendor, you can use the following approach:

Firstly, group your data by both 'Vendor' and 'Month', then calculate the median of the 'Observation' column for each group. This will give you a DataFrame with the desired median values.

Here's how to do it in Python using Pandas:

import pandas as pd
import matplotlib.pyplot as plt

# Group your data by both 'Vendor' and 'Month'
grouped_df = ex_df.groupby(['Vendor', 'Month']).median()['Observation']

# Reset the index to get a DataFrame with 'Vendor', 'Month', and 'Observation' columns
df_median = grouped_df.reset_index()

# Melt the 'Vendor' and 'Month' columns into a single column called 'category'
df_median = pd.melt(df_median, id_vars='Observation', var_name='category')

# Group your data by 'category' (which now contains both vendors and months) and calculate the mean of the 'Observation' column
grouped_median_df = df_median.groupby('category')['Observation'].mean().reset_index()

# Plot the median observations for each month and vendor
plt.figure(figsize=(10, 6))
plt.plot(grouped_median_df['category'], grouped_median_df['Observation'])
plt.xlabel('Month')
plt.ylabel('Median Observations')
plt.title('Median Observations by Month and Vendor')
plt.show()

This code should give you the desired plot showing the median observations for each month and vendor.

As an alternative to plotting, if you want to display the median values in a table or DataFrame, you can use the following code:

print(grouped_df.reset_index().pivot_table('Observation', index='Month', columns='Vendor', aggfunc='median'))

This will give you a pivoted table showing the median observations for each month and vendor.