Home > Enterprise >  Pandas reading CSV as single column
Pandas reading CSV as single column

Time:12-18

I'm trying to load a large CSV file into Pandas, which I'm new to.

The input file should have 13 columns. Howeever, Pandas is reading all of the column headings as one heading, and then just collecting the first few columns of data.

The code I am using is;-

leases=pd.read_csv("/content/LEASES_FULL_2021_12.csv", sep=',', delimiter=None, header=0, names=None, index_col=False, usecols=None, squeeze=False, engine="python")

The CSV is formatted as follows:-

Unique Identifier,Tenure,Register Property Description,County,Region,Associated Property Description ID,Associated Property Description,OS UPRN,Price Paid,Reg Order,Date of Lease,Term,Alienation Clause Indicator

"1608D08BFC5496E31C7926595EE2F1BE278ED436","Leasehold","19 Alcester Crescent, Clapton","GREATER LONDON","GREATER LONDON","501286752","19 ALCESTER CRESCENT, LONDON E5 9PX","10008240310","","2","13-02-1905","99 years from 25 December 1902","N"

"5D0FA4909B7C0FD9477C2275E1948C8F135E233F","Leasehold","7 Agnes Street, Limehouse","GREATER LONDON","GREATER LONDON","3125118","7 AGNES STREET, LONDON E14 7DG","6044926","","2","16-10-1866","99 years from 24 June 1862","N"

etc

The Dataframe then loads with one column as follows:-

enter image description here

Any help would be greatly appreciated.

CodePudding user response:

Try reading it a different way

  data = pd.read_csv(dir, sep=",") 

or

  df = pd.read_csv('input.csv', names=["Name1", "Name2"])  #fill in columns names

CodePudding user response:

I have worked out the solution, the first row of the CSV has no "" around each column name. Resolved now. Thanks for your help.

  • Related