-
-
Save thekvs/793d04bdb1f3d0a0ab54 to your computer and use it in GitHub Desktop.
select and change values in the data frame using frequency criteria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.DataFrame({'a': [1, 2, 3, 3, 4, 1, 7, 8, 9], 'b': [1, 1, 1, 1, 4, 4, 2, 3, 1]}) | |
print(df) | |
print("========") | |
cidx = df.b.value_counts() <= 1 | |
df.loc[df.b.isin(cidx.index[cidx]), 'b'] = 9999 | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment