Created
June 12, 2020 12:14
-
-
Save kaiwei/531eff8ba63fb114658a0a0b05aecea1 to your computer and use it in GitHub Desktop.
Standard Chartered Bank Singapore Bank CSV download cleaner
This file contains 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 numpy as np | |
import sys | |
# Create a Dataframe from CSV | |
df = pd.read_csv(sys.argv[1], thousands = ',', delimiter = ',', skiprows = 5, low_memory = False, keep_default_na = False) | |
# Cleaning: (1) Tabs in columns and headers (2) Make numbers into numbers instead of strings | |
df.columns = df.columns.str.strip() | |
df.Date = df.Date.str.strip() | |
df['Withdrawal'] = '-' + df['Withdrawal'].astype(str) | |
df['Withdrawal'] = df.Withdrawal.replace(r'-', np.nan) | |
# Write to file | |
df.to_csv('clean_' + sys.argv[1], index = False, float_format = '%.2f', encoding = 'utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment