Python: Excel - Bar chart plot

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
887
import pandas as pd
import matplotlib.pyplot as plt
filtered_df = df[df['Hotel Name'] == 'Clayton Hotel']
today_format = datetime.strptime(datetime.today().strftime('%d/%m/%Y'), "%d/%m/%Y")
filtered_df = df[df['Date Captured'] == today_format]
df.plot(x="Check-In", y=["'Current price'"], kind="bar")

Any ideas what I am doing wrong here?

Many thanks.
 
You might need plt.show()
TIMEOUT#! usually means the execution time took too long.
 
Upvote 0
Noticed something else you declared today_format after filtering it. You had it in correct order in post #1 but not #8.
 
Upvote 0
Thanks.

Still no joy with the following, not sure if the order is wrong?

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 = df[df['Date Captured'] == today_format]
df.plot(x="Check-In", y=["Current price"], kind="bar")
filtered_df = df[df['Hotel Name'] == 'Clayton Hotel']
plt.show()
 
Upvote 0
The order is still wrong. Are you plotting df or filtered_df?

Python:
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 = df[(df['Hotel Name'] == 'Clayton Hotel') & (df['Date Captured'] == today_format)]
filtered_df.plot(x="Check-In", y=["Current price"], kind="bar")
plt.show()
 
Upvote 0
Thanks.

Still no joy with the following, not sure if the order is wrong?

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 = df[df['Date Captured'] == today_format]
df.plot(x="Check-In", y=["Current price"], kind="bar")
filtered_df = df[df['Hotel Name'] == 'Clayton Hotel']
plt.show()
You know that this line will output: 2025-02-09 00:00:00
Is this correct for you? Shouldn't be just 2025-02-09?


Regards,
GB
 
Last edited:
Upvote 0
The order is still wrong. Are you plotting df or filtered_df?

Python:
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 = df[(df['Hotel Name'] == 'Clayton Hotel') & (df['Date Captured'] == today_format)]
filtered_df.plot(x="Check-In", y=["Current price"], kind="bar")
plt.show()
This is working! It only displays as an image is this correct?
 
Upvote 0
Thanks,

how do I take 3 days away from: today_format = datetime.strptime(datetime.today().strftime('%d/%m/%Y'), "%d/%m/%Y")

Many thanks.
 
Upvote 0
Python:
from datetime import datetime, timedelta

formatted_date = (datetime.today() - timedelta(days=3)).strftime('%d/%m/%Y')
 
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