mzyxvatA
mzyxvatA

Reputation: 23

Python - How can you plot a data histogram?

I am looking to plot a date histogram. I have a pandas dataframe as follow:

Creation Date  Profile_ID Count
2016-06-01            150
2016-06-03            3
2016-06-04            20 

How can I define the x and y axis of my histogram so that I have a plot of the number of newly-created profile ID per date?

Upvotes: 0

Views: 40

Answers (2)

cph_sto
cph_sto

Reputation: 7607

# Importing the requisite libraries
import pandas as pd
import matplotlib.pyplot as plt

# Creating the DataFrame
df = pd.DataFrame({'Creation Date':['2016-06-01','2016-06-03','2016-06-04'],'Profile_ID Count':[150,3,20]})

# Creating the bar chart below.
fig, ax = plt.subplots()
ax.bar(df['Creation Date'],df['Profile_ID Count'], color='red', width = 0.5)   
fig.autofmt_xdate()   # This tilts the dates displayed along X-axis.
ax.set_title('Creation Date vs. Profile ID Count')
ax.set_xlabel('Creation Date')
ax.set_ylabel('Profile ID Count')
plt.show()

Bar-Chart

Upvotes: 0

luigigi
luigigi

Reputation: 4215

Try:

import matplotlib.pyplot as plt
ax = df.plot.bar(y='Profile_ID Count')
plt.show()

Upvotes: 1

Related Questions