Update pandas data types // Change data types of multiple columns with Python pandas astype

preview_player
Показать описание
Change the data types of your Python pandas dataframes and series columns using pandas astype method. This video from my "Pandas Tips" series demonstrates how you can use Python pandas astype to recast your columns or dataframes from one data type into another. First, we change the current data types of our dataframe using the pandas dtypes property. I'll show you how to update the data types of your entire dataframe first, then we'll use astype to change each column value from an integer into a float. Level up your skills by leveraging the pandas astype mapper. This dictionary-like object allows you to submit the column name as the key and the data type you want as the value. Then you can change the data types of multiple columns at once with just one call to the astype method -- all by supplying a Python pandas mapper object. We do this to convert one column into floats and two others into Boolean data types. You can also make your astype changes permanent by overwriting your pandas dataframe, which we do at the end of the video. Check out this pandas tutorial video to improve your Python pandas knowledge and make the most out of the pandas astype method for changing the data types of your pandas objects!

0:00 Introduction
0:34 Set up and load data
1:09 .dtypes
1:29 Change entire dataframe
2:19 Change one column
3:31 Level UP! mapper
4:50 Multiple columns, different data types
6:33 Permanent changes
7:02 Conclusion & bloopers

💻 Github CODE 💻

🎥 Related VIDEOS 🎥

📖 BOOKS about pandas from my Amazon Storefront 📖

☕ Buy me a COFFEE ☕
If you have enjoyed the content presented in this video and are able, consider buying a virtual cup of coffee to keep my channel going!

#python #pandas #pythonprogramming
Рекомендации по теме
Комментарии
Автор

Hi, Kimberly! Glad to see u again!
There is a small nuance with pandas (numpy) data type 'object'. It's not the same as string column or column containing strings but it is column containg objects those can be integers, strings, booleans, tuples, lists, instances of different classes (e.g., UUID) and so on. There is not special data type for strings but u can convert column values to string using astype('str'):
df = pd.DataFrame(data={'a':[10, True, 'c']})
df.loc[0, 'a']+3 # 13
df=df.astype('str')
df.loc[0, 'a']+'3' # 103
but dtype is object in the both case

mdnpwos
Автор

I really like that jacket/top you're wearing. May I ask what it is/where you got it?

lade_edal