Python chart: Minimum value

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
899
Not sure why this doesn't work?

import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt

today_format = datetime.strptime(datetime.today().strftime('%d/%m/%Y'), "%d/%m/%Y")
filtered_df = values=df['Current price'], aggfunc='min') & (df['Date Captured'] == today_format)]
filtered_df.plot(x="Mon Year", y=["Current price"], kind="bar")
plt.title("Minimum Price")
plt.xlabel("Month Year")
plt.ylabel("Price (£)")
plt.locator_params(axis='x', nbins=12)
plt.show()
 
This is not working as you intended, the df_filtered is only filtering for "Mon Year" = string_date. The first filter gets overridden.

You need both simultaneously like this

Python:
df_filtered = df[(df["Date Captured"].dt.date == today) & (df["Mon Year"] == string_date)]
Thanks a lot works brilliant. When I model a graph for average the graph values come out as decimals. How would I round to the nearest integer?

Pretty sure it is on this part I need to modify the code.

fig, ax = plt.subplots()
p1 = ax.bar(grouped["Check-In"], grouped["Current price"], color='#FFA500')
ax.bar_label(p1, label_type="edge")
ax.bar_label(p1)

Many thanks.
 
Upvote 0
Python:
grouped = df_filtered.groupby("Check-In")["Current price"].min().reset_index() \
    .assign(**{"Current price": lambda x: x["Current price"].round().astype(int)})
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top