[英]How to remove values that do not meet condition from pandas data frame column?
How can I remove under age rows from this data set?如何从此数据集中删除年龄不足的行?
Original dataset原始数据集
ID age
xqd26543231 12
xqd22222231 29
xqd88823231 64
What I tried?我试过什么?
#remove under age users
eligibleAge = myDataFrame['Age']>18
myDataFrame['Age'] = myDataFrame[eligibleAge]
Unexpected result意外的结果
ID age
xqd26543231 xqd26543231
xqd22222231 xqd22222231
xqd88823231 xqd88823231
What I expect我的期望
ID age
xqd22222231 29
xqd88823231 64
I think you can just do myDataFrame = myDataFrame[myDataFrame['Age']>18]
我认为你可以这样做myDataFrame = myDataFrame[myDataFrame['Age']>18]
In your code, myDataFrame['Age'] = myDataFrame[eligibleAge]
right side has different length as left size you are assigning to, and also you are assigning a dataframe onto a serie.在您的代码中, myDataFrame['Age'] = myDataFrame[eligibleAge]
右侧的长度与您分配的左侧尺寸不同,并且您正在将 dataframe 分配给系列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.