Defining Data Type during csv file import based on column index in pandas

后端 未结 3 505
夕颜
夕颜 2020-12-21 09:36

I need to import a csv file that has 300+ columns, among these columns, only the first column needs to specified as a category, while the rest of the columns should be float

3条回答
  •  一向
    一向 (楼主)
    2020-12-21 10:03

    I think the following will serve the purpose:

    df = pd.read_csv(path, low_memory=False, dtype={'Col_A':'category'})
    

    or if you know it will be the first column:

    df = pd.read_csv(path, low_memory=False, dtype={0:'category'})
    

提交回复
热议问题