I have a dataframe that looks like this
d = {'total_time':[1,2,3,4],
'date': ['2022-09-11', '2022-09-11', '2022-09-13', '2022-09-13'],
'key': ['A', 'B', 'A', 'B']}
df_sample = pd.DataFrame(data=d)
df_sample.head()
I want to compare total_time across the data that should be in the x-axis but I want to compare these values by the associated 'key'.
Therefore I should have something that looks like this
CodePudding user response:
You can use seaborn and pass the key column to hue argument :
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
d = {'total_time':[1,2,3,4],
'date': ['2022-09-11', '2022-09-11', '2022-09-13', '2022-09-13'],
'key': ['A', 'B', 'A', 'B']}
df_sample = pd.DataFrame(data=d)
plt.figure()
sb.barplot(data = df_sample, x = 'date', y = 'total_time', hue = 'key')
plt.show()