The next technique related to Data Cleaning is Manipulating Strings. There are dozens of possible ways to manipulate strings including replacing substrings, converting strings to lowercase, uppercase, or title case, and finding the length of a string. This tutorial will cover the following learning objectives:
dataframe['column_name'].str.lower()
dataframe['column_name'].str.upper()
dataframe['column_name'].str.title()
cities['name'].str.lower().str.upper().str.title()
dataframe[dataframe['column_name'].str.startswith('substring')]
dataframe[dataframe['column_name'].str.endswith('substring')]
dataframe[dataframe['column_name'].str.contains('substring')]
dataframe[dataframe['column_name'].isin(['value1', 'value2', 'value3'])]
dataframe[dataframe['column'] [filter]][['column1', 'column2']]
cities[cities['name'].str.endswith('City')][['name', 'population']]
dataframe['column'].unique()
dataframe['column_name'].str.len()
dataframe['column_name'].str.strip()
df.columns = df.columns.str.strip()
dataframe['column_name'].str.replace('old_substring', 'new_substring')
datframe[['new_column1', 'new_column2']] = dataframe['string_column'].str.split(pat='delimiter', n=[num_splits], expand=True)
Congratulations! You just completed the Manipulating Strings Tutorial! To help test your knowledge, let's
practice Formatting, Extracting Information From, and Cleaning Strings.
**It's highly recommended that you
complete the exercise outlined in the previous tutorial before beginning this exercise.**
Have any issues with the above exercise? Post your question on Discord!