2021年3月29日星期一

Python Pandas - how to change datatype of a column and perform the calculations within each cell

I'm trying to multiply out the numbers within the Resolution Column but first I need to convert its data-type from object to int64.

colRes = df['resolution'].astype(str).astype(int)

However, pandas keep giving me the error "invalid literal for int() with base 10: '568x320'".

Any suggestions on how to convert it to the data-type int and then perform the operations within each cell to get the number of pixels?

Resolution Column:

enter image description here

https://stackoverflow.com/questions/66864615/python-pandas-how-to-change-datatype-of-a-column-and-perform-the-calculations March 30, 2021 at 12:01PM

没有评论:

发表评论