2/23/25, 9:17 PM about:blank
Data Analysis with Python
Cheat Sheet: Data Wrangling
Package/Method Description Code Example
Replace missing data with Replace the missing values of the data set attribute with the mode common occurring MostFrequentEntry = df['attribute_name'].value_counts().idxmax()
df['attribute_name'].replace([Link],MostFrequentEntry,inplace=True)
frequency entry in the column.
Replace the missing values of the data set attribute with the mean of all the entries in AverageValue=df['attribute_name'].astype(<data_type>).mean(axis=0)
Replace missing data with mean df['attribute_name'].replace([Link], AverageValue, inplace=True)
the column.
df[['attribute1_name', 'attribute2_name', ...]] =
df[['attribute1_name', 'attribute2_name', ...]].astype('data_type')
Fix the data types Fix the data types of the columns in the dataframe. #data_type is int, float, char, etc.
df['attribute_name'] =
Data Normalization Normalize the data in a column such that the values are restricted between 0 and 1. df['attribute_name']/df['attribute_name'].max()
bins = [Link](min(df['attribute_name']),
max(df['attribute_name'],n)
# n is the number of bins needed
Binning Create bins of data for better analysis and visualization. GroupNames = ['Group1','Group2','Group3,...]
df['binned_attribute_name'] =
[Link](df['attribute_name'], bins, labels=GroupNames, include_lowest=True)
[Link](columns={'old_name':\'new_name'}, inplace=True)
Change column name Change the label name of a dataframe column.
dummy_variable = pd.get_dummies(df['attribute_name'])
Indicator Variables Create indicator variables for categorical data. df = [Link]([df, dummy_variable],axis = 1)
about:blank 1/1