Navigate Select ESC Close

Data Cleaning in Pandas | Python Pandas Tutorials

2023-05-23 Education
542.1k
12.5k
544
Alex The Analyst
Alex The Analyst
1.4m subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

Take my Full Python Course Here: https://www.analystbuilder.com/courses/pandas-for-data-analysis In this series we will be walking through everything you need to know to get started in Pandas! In this video, we learn about Data Cleaning in Pandas. Datasets in GitHub: https://github.com/AlexTheAnalyst/PandasYouTubeSeries/blob/main/Customer%20Call%20List.xlsx Code in GitHub: https://github.com/AlexTheAnalyst/PandasYouTubeSeries/blob/main/Pandas%20101%20-%20Data%20Cleaning%20in%20Pandas.ipynb Favorite Pandas Course: Data Analysis with Pandas and Python - https://bit.ly/3KHMLlu ____________________________________________ SUBSCRIBE! Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content! ____________________________________________ RESOURCES: Coursera Courses: 📖Google Data Analyst Certification: https://coursera.pxf.io/5bBd62 📖Data Analysis with Python - https://coursera.pxf.io/BXY3Wy 📖IBM Data Analysis Specialization - https://coursera.pxf.io/AoYOdR 📖Tableau Data Visualization - https://coursera.pxf.io/MXYqaN Udemy Courses: 📖Python for Data Analysis and Visualization- https://bit.ly/3hhX4LX 📖Statistics for Data Science - https://bit.ly/37jqDbq 📖SQL for Data Analysts (SSMS) - https://bit.ly/3fkqEij 📖Tableau A-Z - http://bit.ly/385lYvN *Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!* ____________________________________________ BECOME A MEMBER - Want to support the channel? Consider becoming a member! I do Monthly Livestreams and you get some awesome Emoji's to use in chat and comments! https://www.youtube.com/channel/UC7cs8q-gJRlGwj4A8OmCmXg/join ____________________________________________ Websites: 💻Website: AlexTheAnalyst.com 💾GitHub: https://github.com/AlexTheAnalyst 📱Instagram: @Alex_The_Analyst ____________________________________________ 0:00 Intro 0:41 First Look at Data 2:34 Removing Duplicates 3:41 Dropping Columns 5:10 Strip 12:15 Cleaning/Standardizing Phone Numbers 21:29 Splitting Columns 24:58 Standardizing Column Values using Replace 28:40 Fill Null Values 29:42 Filtering Down Rows of Data 36:42 Outro *All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for*

Top Comments (10)

@fede77 2023-12-14

For those struggling with the regular expression at 14:57 , you might need to explicitly assign regex = True (based on the FutureWarning displayed in the video). That is: df['Phone_Number'] = df['Phone_Number'].str.replace('[^a-zA-Z0-9]', '', regex=True)

604 69 replies
@rahulraj3855 2023-05-23

Fan from India I just got 2 offers from very good companies thanks to your videos and it helped me transition from a customer success support to Data Analyst

419 20 replies
@tomaronson4419 2024-02-01

For splitting the address at 21:29, you may want to add a named parameter to the value of 2, as in n=2: df[["Street_Address", "State", "Zip_Code"]] = df["Address"].str.split(',', n=2, expand=True)

193 19 replies
@millenniumkitten4107 2023-07-31

Some of the phone numbers are removed while doing the formatting. If you look in the excel file, you'll see that some of the numbers are strings and some are integers. When you run the string method during the formatting, it replaces the numeric values with NaN and they are later removed completely. If you want to avoid losing that data you'll need to use df["Phone_Number"] = df["Phone_Number"].astype(str) before formatting. You also won't need to convert to string in the lambda after doing this.

98 7 replies
@bennet5467 2023-11-12

Thanks for this content, this was so helpful!! I think i have some optimizations, correct me if im wrong :D 27:04 instead of calling the replace function multiple times, you can create a mapping just like: replace_mapping = {'Yes': 'Y', 'No': 'N'} and call it like: df = df.replace(replace_mapping), so you dont have to specify mapping for each column and need to call .replace() just once. 34:16 instead of the for loop + manually dropping row per row, you can make use of the .loc function like: df = df.loc[df["Do_Not_Contact"] == "N"] in order to filter the rows based on filter criterium.

57 4 replies
@HunzaFolk 2024-02-27

I am studying Data Collection and Data Visualization at Kings College, your channel is reccomned by our lecturers to understand data cleaning.

26
@DreaSimply21 2023-10-29

I like how in some of your videos you show us the long way and then the short cut, instead of just showing the short cut. I think that way gives the person who is learning a better breakdown of what they are doing.

14
@itsundisclosed 2025-06-08

14:45 run: df['Phone_Number'].str.replace('[^a-zA-Z0-9]','', regex = True) for newer versions of Anaconda. The code df['Phone_Number'].str.replace('[^a-zA-Z0-9]','') has a potential issue. The regular expression [^a-zA-Z0-9] is correct for matching any non-alphanumeric character, but the .str.replace() method now requires the regex=True parameter to be explicitly set when using regex patterns like this. Without regex=True, pandas will treat the pattern as a literal string, which won't work as intended. 🤝

12
@Elly-we9uc 2023-11-20

Also, to clean the Do_Not_Contact field, one can use: df['Do_Not_Contact'] = df['Do_Not_Contact'].replace({'N': 'No', 'Y': 'Yes'})

10
@sabuhiasadli6083 2024-10-22

what seems to be a daunting task at the beginning turns out to have an easy explanation with the right tools, thank you Alex !!!

6

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot