Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created April 27, 2021 15:05
Show Gist options
  • Select an option

  • Save samirsaci/b3c506960fd3ab2cdda77a9a7eb56af1 to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/b3c506960fd3ab2cdda77a9a7eb56af1 to your computer and use it in GitHub Desktop.
Account Clean
# 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