Created
December 16, 2015 05:49
-
-
Save hsperr/635ff56ece3e23c01d6e to your computer and use it in GitHub Desktop.
replace spaces
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 | |
import re | |
import sys | |
filename = "FILENAME" | |
columns = "COLUMN_NAME" | |
data = pd.read_excel(filename) | |
print(data.columns) | |
def replaceWithSpace(row): | |
return re.sub(r'.([0-9])', '\u202F\1', row) | |
#return row | |
replaced_data = data.copy() | |
replaced_data[columns] = data[columns].apply(replaceWithSpace) | |
replaced_data.to_csv('.'.join(filename.split('.')[:-1])+'.replaced.csv', index=False) | |
replaced_data[~(replaced_data[columns]==data[columns])].to_csv('.'.join(filename.split('.')[:-1])+'.indices.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment