相关疑难解决方法(0)

pandas shift将我的列从整数转换为float.

shift将我的列从整数转换为浮点数.事实证明这np.nan只是浮动.有没有办法将移位列保持为整数?

df = pd.DataFrame({"a":range(5)})
df['b'] = df['a'].shift(1)

df['a']
# 0    0
# 1    1
# 2    2
# 3    3
# 4    4
# Name: a, dtype: int64

df['b']

# 0   NaN
# 1     0
# 2     1
# 3     2
# 4     3
# Name: b, dtype: float64
Run Code Online (Sandbox Code Playgroud)

python numpy pandas

13
推荐指数
2
解决办法
4070
查看次数

标签 统计

numpy ×1

pandas ×1

python ×1