Skip to content

Instantly share code, notes, and snippets.

@moskomule
Created November 18, 2016 14:13
Show Gist options
  • Save moskomule/a534e6feb0bba62bfbcdb2565fbf619a to your computer and use it in GitHub Desktop.
Save moskomule/a534e6feb0bba62bfbcdb2565fbf619a to your computer and use it in GitHub Desktop.
for replacing values of pd.DataFrame
import pandas as pd
csv = pd.read_csv(file_name)
# csv
# "0", "1"
# Tom, 2
# John, 3
#...
csv["2"] = np.zeros(len(csv))
for i in range(len(csv)):
if csv.loc[i, "0"] in persons:
csv.loc[i,"2"] = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment