![](/img/trans.png)
[英]Seaborn TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'
[英]TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe' in seaborn
我的代码:
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)
当我执行最后一行时,它给出了类型错误说
类型错误:无法根据规则“安全”将数组数据从 dtype('int64') 转换为 dtype('int32')
请帮我修复它。 提前致谢。
您可以先将数组转换为 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'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.