tonyibm tonyibm - 4 days ago 6
Python Question

first column name is circled by double quote after reading from csv

i use the following codes to read data from csv using read_csv, but after i print the result and found the first column name is circled by double quote, but other column names are normal,

import pandas as pd
import numpy as np
import csv

path1 = "C:\\Users\\IBM_ADMIN\\Desktop\\ml- 1m\\SELECT_FROM_HRAP2P3_SAAS_ZTXDMPARAM_201611291745.csv"
frame1 = pd.read_csv(path1,encoding='utf8',dtype = {'COMPANY_ORGANIZATION': str})

frame1


The output is here

Answer

I think you can strip column names by value ":

df.columns = df.columns.str.strip('"')

Or if all values contains " use parameter quotechar='"' in read_csv:

Comments