Specifying data type in Pandas csv reader

后端 未结 2 518
旧时难觅i
旧时难觅i 2020-12-13 17:24

I am just getting started with Pandas and I am reading in a csv file using the read_csv() method. The difficulty I am having is preventing pandas from converting my telephon

2条回答
  •  情深已故
    2020-12-13 17:38

    It looks like you can't avoid pandas from trying to convert numeric/boolean values in the CSV file. Take a look at the source code of pandas for the IO parsers, in particular functions _convert_to_ndarrays, and _convert_types. https://github.com/pydata/pandas/blob/master/pandas/io/parsers.py

    You can always assign the type you want after you have read the file:

    df.phone = df.phone.astype(str)
    

提交回复
热议问题