This is my DataFrame:
import pandas as pd
df = pd.DataFrame(
{
'high': [110, 110, 101, 101, 115, 300],
}
)
And this is the expected output. Column bin
should be created:
high bin
0 110 105.0
1 110 105.0
2 101 100.0
3 101 100.0
4 115 111.0
5 300 220.0
Basically bin
is created by using pd.cut
:
import numpy as np
evaluation_bins = [100, 105, 111, 120, 220, np.inf]
df['bin'] = pd.cut(df['high'], bins=evaluation_bins, include_lowest=True, right=False)
This gives me the category itself but I want the left edge as the output.
Honestly there was not much I could try to do. I could get the dtypes
of df
by df.dtypes
but I don’t know how to continue.