2

I want to convert .csv file to dataframe in Python. This is the codes.

import pandas as pd
csv_path = "./table.csv"
df = pd.read_csv(csv_path, error_bad_lines=False)

Below is original form of the .csv file when I opened it using Microsoft's notepad program.

"019E0001"

1    -   019E0001              -  ...            -           -   33312
2    -   019E0002              -  ...            -           -   43211
3    -   019E0003              -  ...            -           -   51588

But, when I read this .csv file in Python by using the function pandas.read_csv(), the value was converted to exponential form. "1.90E+02"

1    -   1.90E+02              -  ...            -           -   33312
2    -   1.90E+03              -  ...            -           -   43211
3    -   1.90E+04              -  ...            -           -   51588

I don't want that change.

I want to reserve the original text form (019E0001)

How could I deal with this problem??

Help me

전은미
  • 21
  • 3

1 Answers1

4

Don't let Pandas infer datatype, so try to append dtype=str as argument of read_csv function:

import pandas as pd
csv_path = "./table.csv"
df = pd.read_csv(csv_path, error_bad_lines=False, dtype=str)  # <- HERE

After that, you can convert your other columns with the right dtype with df.astype({'colX': float, ...})

Corralien
  • 109,409
  • 8
  • 28
  • 52