Python chart: Minimum value

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
887
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()
 
Minimum of the entire column or aggregate min by some other field?
 
Upvote 0
Maybe this.
Python:
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt

df['Date Captured'] = pd.to_datetime(df['Date Captured'], format='%d/%m/%Y')
today_format = datetime.today().strftime('%Y-%m-%d')
grouped_df = df.groupby('Date Captured')['Current price'].min().reset_index()
filtered_df = grouped_df[grouped_df['Date Captured'] == today_format]
filtered_df['Mon Year'] = filtered_df['Date Captured'].dt.strftime('%b %Y')
plt.bar(filtered_df['Mon Year'], filtered_df['Current price'])

plt.title("Minimum Price")
plt.xlabel("Month Year")
plt.ylabel("Price (£)")
plt.show()
 
Upvote 0
Maybe this.
Python:
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt

df['Date Captured'] = pd.to_datetime(df['Date Captured'], format='%d/%m/%Y')
today_format = datetime.today().strftime('%Y-%m-%d')
grouped_df = df.groupby('Date Captured')['Current price'].min().reset_index()
filtered_df = grouped_df[grouped_df['Date Captured'] == today_format]
filtered_df['Mon Year'] = filtered_df['Date Captured'].dt.strftime('%b %Y')
plt.bar(filtered_df['Mon Year'], filtered_df['Current price'])

plt.title("Minimum Price")
plt.xlabel("Month Year")
plt.ylabel("Price (£)")
plt.show()
This is close, this returns the minimum value for all Check-In dates, I'd like all dates to be shown in the data set.
 
Upvote 0
But you want to plot "Month Year" only...confused. Post a sample of your data set.
 
Upvote 0
So it is as below, I'd like "Check-in" date along the x-axis and "Current price" (Minimum) along the y-axis, for today's date as "Date captured"

Hopefully that makes sense?

Date CapturedHotel NameCheck-InCurrent price
2025-02-13Radisson Blu Hotel, Cardiff2025-02-13 £83
2025-02-13Hilton Cardiff2025-02-13 £109
2025-02-13Central Cardiff - 3 Bedroom Home - Free Parking - Walk to Shopping Town Centre And Cardiff Castle2025-02-13 £170
2025-02-13Clayton Hotel Cardiff2025-02-13 £85
2025-02-13The Parkgate Hotel2025-02-13 £103
2025-02-13Sleeperz Hotel Cardiff2025-02-13 £56
2025-02-13Mercure Cardiff Holland House Hotel & Spa2025-02-13 £89
2025-02-13Novotel Cardiff Centre2025-02-13 £84
2025-02-13Park Plaza Cardiff2025-02-13 £92
2025-02-13Leonardo Hotel Cardiff2025-02-13 £89
2025-02-13Park Inn by Radisson Cardiff City Centre2025-02-13 £89
2025-02-13Cardiff Marriott Hotel2025-02-13 £114
2025-02-13The Angel Hotel2025-02-13 £60
2025-02-13Holiday Inn Cardiff City by IHG2025-02-13 £85
2025-02-13Cardiff Sandringham Hotel2025-02-13 £43
2025-02-13Hotel Indigo - Cardiff by IHG2025-02-13 £99
2025-02-13ML Lodge2025-02-13 £47
2025-02-13Dray Court - Luxury 2 Bedroom Apartment2025-02-13 £156
2025-02-13Sky Night Serviced Apartments2025-02-13 £98
 
Upvote 0

Forum statistics

Threads
1,226,831
Messages
6,193,207
Members
453,779
Latest member
C_Rules

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