Oct-01-2021, 03:36 PM
(This post was last modified: Oct-01-2021, 05:24 PM by deanhystad.)
You are measuring how long it takes the for loop to do 10 plots.
Why are you doing this:
If you want counts for df['DTE'] < 251 let pandas do the work for you. In the example below I plot the count of df['DTE'] for DET values in the range 20 to 50.
Why are you doing this:
plt.bar(key,my_dict[key])I assume that plt is mathplotlib.pyplot and that you want to plot df['DTE'] counts for df['DTE'] < 251. What your code does is make a bunch of bar charts where each chart has 1 bar.
If you want counts for df['DTE'] < 251 let pandas do the work for you. In the example below I plot the count of df['DTE'] for DET values in the range 20 to 50.
import random import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame({'DTE':[random.randint(1,101) for _ in range(1000)]}) counts = df.loc[(df['DTE'] >= 20) & (df['DTE'] <= 50)].value_counts().sort_index(ascending=True) counts.plot(kind='bar') plt.show()