-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
41 lines (28 loc) · 913 Bytes
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Functions
import pandas as pd
import numpy as np
def standarizate_cols (df):
'''
Standarizes column names
- Sets cols to lowercase.
- Replaces empty space for '_'.
Args:
df: The dataframe to be standarized.
Returns:
A df that has been standarized.
'''
df.columns = df.columns.str.lower().str.replace(' ', '_')
return df
def nulls_percent (df):
'''
Shows percent of nulls in a data frame.
Args:
df: The dataframe we want to check out.
Returns:
A new df with 2columns:
- 'column_name' with the name of the original df columns
- 'nulls_percentage' with the percentage of nulls in every column
'''
nulls_percent = pd.DataFrame(df.isna().sum()/len(df)).reset_index()
nulls_percent.columns = ['column_name', 'nulls_percentage']
return nulls_percent