Last active
March 17, 2018 10:21
-
-
Save okdolly-001/da9a364e83ae5167ab8cf801ebadaa6b to your computer and use it in GitHub Desktop.
delete part of a string in pandas #pandas #python
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
#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