Created
April 27, 2021 15:05
-
-
Save samirsaci/b3c506960fd3ab2cdda77a9a7eb56af1 to your computer and use it in GitHub Desktop.
Account Clean
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
| # Function to open and clean | |
| def clean(file_raw, month): | |
| # Open the file and start from line 5 | |
| df_raw = pd.read_excel(file_raw, header = 5) | |
| df_raw.head() | |
| # Remove First Lines | |
| df_clean = df_raw.copy() | |
| df_clean = df_clean.iloc[4:] | |
| # FillNa with '-' (strings) | |
| for col in df_raw.columns[0:2]: | |
| df_clean[col] = df_clean[col].fillna('-') | |
| # FillNa with 0 (numeric) | |
| for col in df_raw.columns[2:]: | |
| df_clean[col] = df_clean[col].fillna(0).round(1) | |
| # TRIM Column values | |
| df_clean.columns = [str(t).strip() for t in df_clean.columns] | |
| return df_clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment