From the course: Python in Excel: Working with pandas DataFrames
Unlock the full course today
Join today to access over 23,300 courses taught by industry experts.
Working with text data
From the course: Python in Excel: Working with pandas DataFrames
Working with text data
- [Instructor] One thing Python is really good at is text manipulation. So let's see how we can access Python's string methods to clean up messy DataFrame columns. When you let users type in their name or address, you'll end up with a bunch of malformed text, like, we can see here in column B. There's always someone who has caps lock on and spaces at the beginning or end of the text is also very common. As usual, in the first cell K1 here, we are merely turning the data into a DataFrame. So let's get straight into cell K2. That shows us how to access Python's string methods from a DataFrame column. So to strip off any white space at the beginning and end of the word, we can use the strip method, but importantly, to do so, we need to use the str attribute on the DataFrame column. In the preview, we can see that all names are now properly aligned. However, there is still something going on with the capitalization. To make every word start with a capital letter, we can use the title…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.