Skip to content
Advertisement

Pandas how to count when string values converted to_numeric is greater than N?

I have monthly dataframe (df) that is already in min – max ranges like the below:

JavaScript

I want to know the number of times the max wind speed was below the calib number each month. So I am trying to create a column Speed below calib (sbc) like below.

JavaScript

The above code is not working and I am getting the error AttributeError: 'DataFrame' object has no attribute 'str'. How would I fix this?

Advertisement

Answer

You can use melt:

JavaScript

Output:

JavaScript

Step by step:

  1. Reshape your dataframe
JavaScript
  1. Extract max wind from range
JavaScript
  1. Filter out rows and count
JavaScript

Finally map (merge) this series to your original dataframe.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement