pandas shift converts my column from integer to float.

后端 未结 5 1183
一整个雨季
一整个雨季 2020-12-10 12:14

shift converts my column from integer to float. It turns out that np.nan is float only. Is there any ways to keep shifted column as integer?

<
5条回答
  •  无人及你
    2020-12-10 12:58

    another solution starting from pandas version 0.24.0: simply provide a value for the parameter fill_value:

    df['b'] = df['a'].shift(1, fill_value=0)
    

提交回复
热议问题