Reputation: 1754
pd.cut(df['a'],[0,2,4,10,np.inf],right=False)
It returns [0,2),[2,4),[4,10),[10,np.inf)
.
But how can I get [0],(0,2),[2,4),[4,10),[10,np.inf)
?
Upvotes: 0
Views: 65
Reputation: 2643
If all values are integers and greater than zero, this could work:
import numpy as np
import pandas as pd
df = pd.DataFrame({'a': [1, 3, 5, 7, 9, 11, 13]})
pd.cut(df['a'], [-np.inf, 1, 2, 4, 10, np.inf], right=False)
Upvotes: 1