Skip to content

Instantly share code, notes, and snippets.

@indera
Created April 13, 2018 14:05
Show Gist options
  • Save indera/0478be912adce630df2c3782425db03f to your computer and use it in GitHub Desktop.
Save indera/0478be912adce630df2c3782425db03f to your computer and use it in GitHub Desktop.
import pandas as pd
bad_px = ["12", "34"]
df = pd.DataFrame({
"px_id": [1, 2, 3],
"px": ["12", "34", "56"],
"px_type": ["10", "10", "09"]
})
print("Original: \n{}".format(df))
index = df["px"].isin(bad_px)
df.ix[index, "px_type"] = '09'
print("Fixed: \n {} ".format(df))
# Original:
# px px_id px_type
# 0 12 1 10
# 1 34 2 10
# 2 56 3 09
# Fixed:
# px px_id px_type
# 0 12 1 09
# 1 34 2 09
# 2 56 3 09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment