Pandas.read_csv moves column names by one

I am using the ALL.zip file located here . My goal is to create a pandas DataFrame with it. However, if I run

data=pd.read_csv(foo.csv)

column names do not match. The first column has no name, and then the second column is marked first, and the last column is the NaN series. So I tried

colnames=[list of colnames]
data=pd.read_csv(foo.csv, names=colnames, header=False)

who gave me the same thing so I ran

data=pd.read_csv(foo.csv, names=colnames)

which perfectly arranged the columns but had the names of the assigned csv columns (first row in the csv document), perfectly aligned as the first row of data. Therefore i ran

data=data[1:]

who did the trick.

, . read_csv , pd.read_csv, ,

( , , )? read_csv?

2 csv

cmte_id,cand_id,cand_nm,contbr_nm,contbr_city,contbr_st,contbr_zip,contbr_employer,contbr_occupation,contb_receipt_amt,contb_receipt_dt,receipt_desc,memo_cd,memo_text,form_tp,file_num,tran_id,election_tp
C00458844,"P60006723","Rubio, Marco","HEFFERNAN, MICHAEL","APO","AE","090960009","INFORMATION REQUESTED PER BEST EFFORTS","INFORMATION REQUESTED PER BEST EFFORTS",210,27-JUN-15,"","","","SA17A","1015697","SA17.796904","P2016",
+4
2

, ,

import pandas as pd

df = pd.read_csv('P00000001-ALL.csv', index_col=False, low_memory=False)

print(df.head(1))

     cmte_id    cand_id       cand_nm           contbr_nm contbr_city  \
0  C00458844  P60006723  Rubio, Marco  HEFFERNAN, MICHAEL         APO   

  contbr_st contbr_zip                         contbr_employer  \
0        AE  090960009  INFORMATION REQUESTED PER BEST EFFORTS   

                        contbr_occupation  contb_receipt_amt contb_receipt_dt  \
0  INFORMATION REQUESTED PER BEST EFFORTS                210        27-JUN-15   

  receipt_desc memo_cd memo_text form_tp  file_num      tran_id election_tp  
0          NaN     NaN       NaN   SA17A   1015697  SA17.796904       P2016  

low_memory=False , 6 .

+8

- , ( ). Pandas , " " .

data= pd.read_csv('P00000001-AL.csv',index_col=False)
+6

Source: https://habr.com/ru/post/1609864/


All Articles