Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

以下语句,目的是求data中每一行的数据是否完全一样,
tag = data.apply(lambda x: (x == np.mean(x)).all(), axis=1)
当数据量在15万以下时,没有什么问题
但当跑到20万数据时,
报type error错:
TypeError: can only concatenate str (not "int") to str
当然,数据我保证都是 INT
而且,以下语句
print(sub_data.isna().any().any())
输出为 False
这是为什么呢?

而语句
tag = (data.T.mean() == data.T).all()
表现无异常

原因找到了:是数据中存在str
df.mean() 操作时,存在类型为object的数据不会输出,所以,某列数据为object时,df.T之后再做mean操作,返回的时空series,尽管语句
(data.T.mean() == data.T).all()
没有报错,但其返回值都为False

语句tag = data.apply(lambda x: (x == np.mean(x)).all(), axis=1)
报错,就好理解了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...