python筛选excel某一列中相同的数据报错
import pandas as pd
data = pd.read_excel('1.xlsx',encoding = 'gbk')
data_gender = data[['ID','Price','Actualamount','Merchandise','Time','Place']]
data_gender_re = data_gender
FF = data_gender_re.loc[(data_gender_re['Place'] == 'A')]
print(data_gender_re.loc[(data_gender_re['Place'] == 'A')])
FF.to_excel('C:\\Users\\Administrator\\Desktop\\A.xlsx',index=False,encoding = 'gbk')
我按照这些代码对excel某一列相同的数据进行了筛选,发现抱错:invalid type comparison
然后使用了converters={'from':str,'to':str}进行修改,未果,求助。(数据表当中merchandise列内容为字符串,其他均为纯数字列或纯字母列) 文件分享下,报错贴全。 suchocolate 发表于 2022-5-2 23:19
文件分享下,报错贴全。
https://blog.csdn.net/ljlchrr/article/details/84025848按照这篇文章的代码,数据内容和上面的基本一致。下面是具体报错内容:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\ops.py:816: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
result = getattr(x, name)(y)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-23-64df86877057> in <module>()
4 data_gender = data[['Student ID','Correct','Score','Problem ID','Assignment ID','Assignment Title']]
5 #筛选Place中地点为A 的数据
----> 6 FF = data_gender.loc[(data_gender['Problem ID'] == '514524')]
7 print(data_gender.loc[(data_gender['Problem ID'] == '514524')])
8 FF.to_csv('test1.xlsx',index=False,encoding = 'gbk') #生成excel文件
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\ops.py in wrapper(self, other, axis)
877
878 with np.errstate(all='ignore'):
--> 879 res = na_op(values, other)
880 if is_scalar(res):
881 raise TypeError('Could not compare {typ} type with Series'
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\ops.py in na_op(x, y)
816 result = getattr(x, name)(y)
817 if result is NotImplemented:
--> 818 raise TypeError("invalid type comparison")
819 except AttributeError:
820 result = op(x, y)
TypeError: invalid type comparison suchocolate 发表于 2022-5-2 23:19
文件分享下,报错贴全。
https://wwn.lanzouj.com/is81e046r6nc suchocolate 发表于 2022-5-2 23:19
文件分享下,报错贴全。
审核需要较长的时间,https://请wwn.l删除anzouj.c中间的om/is81文字e046r6nc suchocolate 发表于 2022-5-2 23:19
文件分享下,报错贴全。
这个门题没有了,但出现了新的问题故重新发帖
页:
[1]