Skip to content

Instantly share code, notes, and snippets.

@okdolly-001
Last active March 17, 2018 10:21
Show Gist options
  • Save okdolly-001/da9a364e83ae5167ab8cf801ebadaa6b to your computer and use it in GitHub Desktop.
Save okdolly-001/da9a364e83ae5167ab8cf801ebadaa6b to your computer and use it in GitHub Desktop.
delete part of a string in pandas #pandas #python
#deleting a char directly in csv
infile = "test.csv"
outfile = "test_edit.csv"
delete_list = ["b'", "'"]
fin = open(infile)
fout = open(outfile, "w+")
for line in fin:
for word in delete_list:
line = line.replace(word, "")
fout.write(line)
fin.close()
fout.close()
#strip a part of a string in pandas
df = pd.read_csv('data/test.csv')
df['f769'] = df['f769'].str.rstrip("'")
df.to_csv('data/test.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment