pandas cut a series with nan values
问题 I would like to apply the pandas cut function to a series that includes NaNs. The desired behavior is that it buckets the non-NaN elements and returns NaN for the NaN-elements. import pandas as pd numbers_with_nan = pd.Series([3,1,2,pd.NaT,3]) numbers_without_nan = numbers_with_nan.dropna() The cutting works fine for the series without NaNs: pd.cut(numbers_without_nan, bins=[1,2,3], include_lowest=True) 0 (2.0, 3.0] 1 (0.999, 2.0] 2 (0.999, 2.0] 4 (2.0, 3.0] When I cut the series that