hafiz031
hafiz031

Reputation: 2670

How to work on a portion of a histogram in python

enter image description here

Hi! I have come up with a bimodal graph like this on which I want to find min, max, mode, median and standard deviation of distribution. But I am only interested on a portion of this complete histogram. I want to find these values only for the left side of it (that is for the left mode and its surroundings). So for this reason I want to divide the histogram into two parts based on X axis ([0, 0.25] and [0.25, 0.4] say) before passing it to respective numpy/statistics/scipy functions. I want to pass the [0, 0.25] portion only. How can I achieve that?

Upvotes: 0

Views: 329

Answers (1)

NicolaiF
NicolaiF

Reputation: 1343

You write you used a pandas dataframe to plot it. So I am assuming you have a dataframe to work on.

If you only want to pass values between an interval you can slice it using pandas slicing, this is assuming your X data is stored in a column called "X":

from_x = 0
to_x = 0.25
data_with_values_in_X_interval= data[(data["X"] >= from_x) & (data["X"] <= to_x)]

Then you can plot the DataFrame the same way as you did before

Upvotes: 1

Related Questions