如何使用 Python 删除 Excel 文件中具有特定值的列中的行
How to remove rows in a column with certain value in Excel file with Python
我有这样的数据:
我想删除用户ID_2列中数据大于和小于5位的行
Select 必填列并检查 value/10000 > 0 是否超过 5 位。然后用 null 或任何东西替换该值。基本上你是在过滤数据。
https://www.geeksforgeeks.org/python-filtering-data-with-pandas-query-method/
既然问题是
which the data is more than and less than 5 digit
这意味着只需要 5 位数的值,我稍微修改了@ChrisA 评论以符合要求:
df = pd.DataFrame({'userID': [20394756382,29304857203,20294857642,20293847564,20192837453],
'UserID2' : [38493,2212324,30498,30928,432]})
df = df.loc[df['UserID2'].astype(str).str.len().eq(5)]
print(df)
userID UserID2
0 20394756382 38493
2 20294857642 30498
3 20293847564 30928
我有这样的数据:
我想删除用户ID_2列中数据大于和小于5位的行
Select 必填列并检查 value/10000 > 0 是否超过 5 位。然后用 null 或任何东西替换该值。基本上你是在过滤数据。
https://www.geeksforgeeks.org/python-filtering-data-with-pandas-query-method/
既然问题是
which the data is more than and less than 5 digit
这意味着只需要 5 位数的值,我稍微修改了@ChrisA 评论以符合要求:
df = pd.DataFrame({'userID': [20394756382,29304857203,20294857642,20293847564,20192837453],
'UserID2' : [38493,2212324,30498,30928,432]})
df = df.loc[df['UserID2'].astype(str).str.len().eq(5)]
print(df)
userID UserID2
0 20394756382 38493
2 20294857642 30498
3 20293847564 30928