2024-04-17 21:57:17 发布
网友
我想创建一个长度为4的列表
我有一个df
contents values 0 A 484 1 B 429 2 C 130 3 D 108 4 E 77 5 F 2
我想为这些值定义一个bin范围。 我试图得到一个df值在什么范围内 这里,我的最大值是484。你知道吗
my_max=468, it should give round-off values in the list my desired output is, output_list=[0,100,300,500]
如果您知道最多有三位数字,则可以使用:
int(round(484,-2))
输出:
=> 500
此函数的一般化是(将484替换为value):
484
int(round(484,-(len(str(484))-1)))
使用np.linspace
np.linspace
In [1212]: np.linspace(0, round(df['values'].max(), -2), len(df)) Out[1212]: array([ 0., 100., 200., 300., 400., 500.])
如果您知道最多有三位数字,则可以使用:
输出:
此函数的一般化是(将
484
替换为value):输出:
使用
np.linspace
相关问题 更多 >
编程相关推荐