value_count出现警告,该如何改?
统计Dataframe中超市那行出现的每个元素的数量再把前30的数量加起来。
源码
shuliang=hang['超市'].value_counts()
zongshu = sum(shuliang[:30])
出现警告:
E:\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_utils.py:605: FutureWarning: The behavior of `series` with an integer-dtype index is deprecated. In a future version, this will be treated as *label-based* indexing, consistent with e.g. `series` lookups. To retain the old behavior, use `series.iloc`. To get the future behavior, use `series.loc`.
s = s[:max_items]
E:\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_utils.py:606: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
for item in s.iteritems():
这代码该怎么改才能不出现红色的提醒。 你这种表达方式怎么都看不明白 chinajz 发表于 2023-1-14 17:12
你这种表达方式怎么都看不明白
由于调试到那两行,才出现红色报警,所以只复制了那两行
前面是各种impor
hang=pd.read_csv('A.csv')#读取csv文件到dataframe
shuliang=hang['超市'].value_counts()#从dataframe中超市的列,统计该列出现元素的次数
zongshu = sum(shuliang[:30]) #把统计的前30名的元素,进行累加。
print(zongshu)
望大神帮忙看下,如何才能不出现警告。 skyhouse 发表于 2023-1-14 18:38
由于调试到那两行,才出现红色报警,所以只复制了那两行
前面是各种impor
hang=pd.read_csv('A.csv') ...
看看文件,这不就是python 和 模块的兼容问题 吗?有警告不伤大雅,能用就行
E:\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_utils.py
升级降级 模块 试试。 本帖最后由 chinajz 于 2023-1-15 08:52 编辑
skyhouse 发表于 2023-1-14 18:38
由于调试到那两行,才出现红色报警,所以只复制了那两行
前面是各种impor
hang=pd.read_csv('A.csv') ...
zongshu = sum(shuliang[:30])
按信息:To retain the old behavior, use `series.iloc`. To get the future behavior, use `series.loc`.
改为
zongshu = sum(shuliang)
试试
.value_counts()函数这种用法不常见,是不是要改一下?
shuliang=value_counts(hang['超市']) chinajz 发表于 2023-1-15 08:36
zongshu = sum(shuliang[:30])
按信息:To retain the old behavior, use `series.iloc`. To get th ...
改了,不行,还是很多红色提示。。。。 ba21 发表于 2023-1-14 20:17
看看文件,这不就是python 和 模块的兼容问题 吗?有警告不伤大雅,能用就行
E:\PyCharm Community Edit ...
多谢,我试试
页:
[1]