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

aoz*_*ozk 0 python pandas seaborn

我有 DataFrame 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
Run Code Online (Sandbox Code Playgroud)

number_col :

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
Run Code Online (Sandbox Code Playgroud)

我想使用seaborn和列number_col绘制直方图

>     import seaborn as sns
>     
>     sns.distplot(df, x='number_col')
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

ValueError: could not convert string to float: 'number_col'
Run Code Online (Sandbox Code Playgroud)

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

Daw*_*weo 5

sns.distplot确实需要系列、一维数组或列表。作为第一个参数,不是完整的pandas.DataFrame,尝试替换

sns.distplot(df, x='number_col')
Run Code Online (Sandbox Code Playgroud)

使用

sns.distplot(df['number_col'])
Run Code Online (Sandbox Code Playgroud)

单列在 的文档pandas.DataFramepandas.Series称为系列snd.distplot