I have a very large data framework that I would like to avoid iterating through each row and want to convert the entire column from a hexadecimal string to int. It does not handle the string correctly with astype, but has no problems with a single entry. Is there any way to tell astype that the data type is base 16?
IN: import pandas as pd df = pd.DataFrame(['1C8','0C3'], columns=['Command0']) df['Command0'].astype(int) OUT: ValueError: invalid literal for int() with base10: '1C8'
This works, but you want to avoid string iteration.
for index, row in df.iterrows(): print(row['Command0'])
I am reading this from CSV pd.read_csv(open_csv, nrows=20) , so if there is a way to read it and I will explicitly say what format it will be then it will be even better!
source share