2

I have a csv which has a column that contains a long "ID" string such as 9075841942209708806(int64). Now, when I read this csv file into a pandas data frame, this number turns into -9.191700e+18(float64).

How can the id of -9.191700e+18(float64) be converted in its original form, i.e. 9075841942209708806(int64)?

5
  • df = pd.read_csv(file, dtype={'ID':np.int64}) Commented Aug 21, 2018 at 12:38
  • Oh, I am sorry for the confusion but if the id column is not labelled and thus only column 1 for example, how would that change the code? I tried df = pd.read_csv(file, dtype={'1':np.int64}) but it didnt work...can you help please? Commented Aug 21, 2018 at 12:49
  • What about df = pd.read_csv(file, dtype={1:np.int64}, header=None) ? Commented Aug 21, 2018 at 12:51
  • It somewhat worked. So, now the issue is that the int values do not match anymore with the original ones. For example: original one is 9075841942209708806 and converted one is 9075800000000000000...what can this be due to? Commented Aug 21, 2018 at 13:04
  • Hmmm, is possible working with strings? like df = pd.read_csv(file, dtype={1:'str'}, header=None) Commented Aug 21, 2018 at 13:09

1 Answer 1

2

To change dtype of column you need to use:

 df['ID'] = df['ID'].astype('int64')

Documentation here: LINK

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.