在熊猫数据框中将索引值设置为 np.uint64 将其类型更改为 int64

问题描述

我正在尝试在熊猫数据框的索引上设置 dtype

import pandas as pd
import numpy as np
a = pd.DataFrame(columns=['value'])
a.loc[np.uint64(3)] = [3]

# Here I would expect to get UINT64 but it's INT64
a.index.dtype
> dtype('int64')

a.index = a.index.astype(np.uint64)

# Works as expected
a.index.dtype
> dtype('uint64')

a.loc[np.uint64(4)] = [4]

# Now I am getting totally confused. Why do I get float64 ?
a.index.dtype
> dtype('float64')
  • 为什么 Panda 不使用传递给 lob 函数的索引值的 DType
  • 为什么 dtype 会随机改变?

我错过了什么?一劳永逸地设置索引类型的正确方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)