python中整数类型的数值一定不会出现小数点_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)

but getting the following error message:

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 cannot plot category datatypes. You would need to convert to a string.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值