有一个熊猫数据框,我如何有效地删除属性类中具有特定值(例如“ low ”)的行的一部分?这是我的代码:
import pandas as pd
import numpy as np
np.random.seed(3)
df = pd.DataFrame({"a":[1,2,3,4], "b":[5,6,7,8], "class":['High','Low','Low','Low']})
drop_indices = np.random.choice(df.index, int(np.ceil(0.5*df.shape[0])) , replace=True)
df_subset = df.drop(drop_indices)
print df
print df_subset
输出:
a b class
0 1 5 High
1 2 6 Low
2 3 7 Low
3 4 8 Low
a b class
1 2 6 Low
3 4 8 Low
从所有类中删除,我希望从类=仅低级中删除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句