TypeError:无法根据seaborn中的“安全”规则将数组数据从dtype('int64')强制转换为dtype('int32')

问题描述 投票:0回答:1

我的代码:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

data = sns.load_dataset("tips")

sns.lineplot(x="total_bill",y = "size",data = data)

当我执行最后一行时,它给出了类型错误说明

TypeError:无法将数组数据从dtype('int64')转换为dtype('int32')根据规则“安全”

请帮助我修复它。预先感谢。

python machine-learning seaborn valueerror
1个回答
-1
投票

您可以像这样将数组先转换为int32:

x = np.array([1, 2, 3, 4], dtype=np.int64)
print(type(x[0]))

>> <class 'numpy.int64'>

x = np.array(x, dtype=np.int32)
print(type(x[0]))

>> <class 'numpy.int32'>
© www.soinside.com 2019 - 2024. All rights reserved.