seaborn:无法将字符串转换为浮点

2024-05-03 04:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有数据帧df

Timestamp-start    datetime64[ns]
Timestamp-end      datetime64[ns]
M                          object
S                          object
Type                       object
description_x              object
description_y              object
Date               datetime64[ns]
number_col                 float64
dtype: object

编号\u列

51      0.0
0       1.0
1       2.0
2       3.0
52      5.0
      ...  
47    148.0
48    148.0
43    148.0
49    149.0
50    149.0
Name: number_col, Length: 132, dtype: float64

我想用seaborn和columnnumber\u col

>     import seaborn as sns
>     
>     sns.distplot(df, x='number_col')

但我犯了以下错误:

ValueError: could not convert string to float: 'number_col'

我不知道为什么会发生这种情况,“number_col”已经是一个浮点列了


Tags: 数据numberdfobjectcoldescriptionseabornstart
2条回答

^{}不需要系列、1d数组或列表作为第一个参数,不是完整的pandas.DataFrame,请尝试替换

sns.distplot(df, x='number_col')

使用

sns.distplot(df['number_col'])

在{a2}中,{}的单列被{}称为系列

我发现^{}不受欢迎。相反,我们应该使用^{}

^{}的第一个参数中,我们可以把pandas.DataFrame放在:

sns.displot(df, x='number_col')

相关问题 更多 >