change dataframe column type

Do you want to know the details regarding “change dataframe column type”. If yes, you’re in the correct article.

change dataframe column type

# You can use "astype" method
# suppose you want to correct your "sales" column data type
df['sales'] = df['sales'].astype('float64')
>>> df.astype('col1': 'int32').dtypes
col1    int32
col2    int64
dtype: object
df.astype(int)
df = pd.read_csv("weather.tsv", sep="t",  
                 dtype='Day': str,'Wind':int64)
df.dtypes

Conclusion

I hope this tutorial helps you to know about “change dataframe column type”. If you have any questions regarding this post please let us know via the comment section. Share this post with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment