Numbers inside a pandas dataframe have changed

153 Views Asked by At

I am a beginning programmer and currently working in Dataiku on a dataset with around 27000 records. The original/parent dataset has telephone numbers stored inside a string element, for example '0612345678' and '0229123456'.

However, when I load this dataset into my python script the datatype AND the numbers inside the columns changed. The column is now a float64 object and the telephone numbers from the example look as follows: '612345678.0' and '229123456.0'.

I tried to change the column data type using df['telephone_number'].astype(str) and the data type did change. However, the numbers are still showed in the wrong way ('612345678.0'). Can anyone please help me to change the numbers back to their original shape so that I can use them for my future analysis?

1

There are 1 best solutions below

0
On

You can specify which type you want to read a specific column as.

df = pd.read_csv("your_file.csv", dtype={'TelephoneNum': str})