如何解决在熊猫数据框中将索引值设置为 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 举报,一经查实,本站将立刻删除。