Python:float()参数必须是字符串或数字,而不是'pandas [英] Python: float() argument must be a string or a number,not 'pandas

查看:1424
本文介绍了Python:float()参数必须是字符串或数字,而不是'pandas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下代码,我试图通过这些代码来绘制图形:

Have the following piece of code through which I am trying to plot a graph:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import mpld3



my_list = [1,2,3,4,5,7,8,9,11,23,56,78,3,3,5,7,9,12]

new_list = pd.Series(my_list)

df1 = pd.DataFrame({'Range1':new_list.value_counts().index, 'Range2':new_list.value_counts().values})

df1.sort_values(by=["Range1"],inplace=True)

df2 = df1.groupby(pd.cut(df1["Range1"], [0,1,2,3,4,5,6,7,8,9,10,11,df1['Range1'].max()])).sum()

objects = df2['Range2'].index

y_pos = np.arange(len(df2['Range2'].index))

plt.bar(df2['Range2'].index.values, df2['Range2'].values)

但收到以下错误消息:

TypeError: float() argument must be a string or a number, not 'pandas._libs.interval.Interval'

无法从此浮动错误发生的地方获取信息.任何建议都将受到高度赞赏.

Not getting from where this float error is coming. Any suggestion is highly appreciated.

推荐答案

Matplotlib无法绘制category数据类型.您将需要转换为字符串.

Matplotlib cannot plot category datatypes. You would need to convert to a string.

plt.bar(df2['Range2'].index.astype(str), df2['Range2'].values)

这篇关于Python:float()参数必须是字符串或数字,而不是'pandas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆