0

Have to create a histogram, neglecting the values higher than constant

I try this:

plt.hist(df[df['avg_speed'] < 1])
plt.show()

but it's not working, because of comparison returns the boolean values. How to repair it?

Axmed
  • 41
  • 4

2 Answers2

0
sub_df = df.loc[df['avg_speed'] <1] 

plt.hist(sub_df)
BlackMath
  • 1,708
  • 1
  • 11
  • 14
0

I suggest you check the types of your dataframe columns printing df.dtypes is one way of doing it.

Make sure they integers (int64).

I tried your code and it works with a simple table.

    import pandas as pd

    data = {"avg_speed": [1,2,3,4,5,6]}
    df = pd.DataFrame(data)
    table = df[df["avg_speed"] > 1]
    plt.hist(table.avg_speed)
    plt.show()
kodkirurg
  • 156
  • 8