MATLAB: Read CSV with row in quotes (string and numbers)

csvloadreadtable

I have no idea to read the .CSV file correctly.
Here are the titles incl. the first three rows as example (in the File, there are over 22'000):
id,date,price,bedrooms,bathrooms,sqft_living,sqft_lot,floors,waterfront,view,condition,grade,sqft_above,sqft_basement,yr_built,yr_renovated,zipcode,lat,long,sqft_living15,sqft_lot15
"7129300520,""20141013T000000"",221900,3,1,1180,5650,""1"",0,0,3,7,1180,0,1955,0,""98178"",47.5112,-122.257,1340,5650"
"6414100192,""20141209T000000"",538000,3,2.25,2570,7242,""2"",0,0,3,7,2170,400,1951,1991,""98125"",47.721,-122.319,1690,7639"
"5631500400,""20150225T000000"",180000,2,1,770,10000,""1"",0,0,3,6,770,0,1933,0,""98028"",47.7379,-122.233,2720,8062"
Every row is in quotes, and the data are strings (double quotes) and numbers. The demiliter is the comma ",".
I tried this:
opts = detectImportOptions('house_data.csv')
T = readtable('house_data.csv', opts);
But what I get is a nx1-table but it should be nx21-table (21 is the amount of the features [id, date, price, bedroms, …])

Best Answer

I have no idea to read the .CSV file correctly.
One approach:
C = {"7129300520,""20141013T000000"",221900,3,1,1180,5650,""1"",0,0,3,7,1180,0,1955,0,""98178"",47.5112,-122.257,1340,5650"
"6414100192,""20141209T000000"",538000,3,2.25,2570,7242,""2"",0,0,3,7,2170,400,1951,1991,""98125"",47.721,-122.319,1690,7639"
"5631500400,""20150225T000000"",180000,2,1,770,10000,""1"",0,0,3,6,770,0,1933,0,""98028"",47.7379,-122.233,2720,8062"};
Vn = {'id','date','price','bedrooms','bathrooms','sqft_living','sqft_lot','floors','waterfront','view','condition','grade','sqft_above','sqft_basement','yr_built','yr_renovated','zipcode','lat','long','sqft_living15','sqft_lot15'};
T1 = array2table(squeeze(split([C{:}], ',')),'VariableNames',Vn);
producing:
T1 =
3×21 table
id date price bedrooms bathrooms sqft_living sqft_lot floors waterfront view condition grade sqft_above sqft_basement yr_built yr_renovated zipcode lat long sqft_living15 sqft_lot15
____________ ___________________ ________ ________ _________ ___________ ________ ______ __________ ____ _________ _____ __________ _____________ ________ ____________ _________ _________ __________ _____________ __________
"7129300520" ""20141013T000000"" "221900" "3" "1" "1180" "5650" ""1"" "0" "0" "3" "7" "1180" "0" "1955" "0" ""98178"" "47.5112" "-122.257" "1340" "5650"
"6414100192" ""20141209T000000"" "538000" "3" "2.25" "2570" "7242" ""2"" "0" "0" "3" "7" "2170" "400" "1951" "1991" ""98125"" "47.721" "-122.319" "1690" "7639"
"5631500400" ""20150225T000000"" "180000" "2" "1" "770" "10000" ""1"" "0" "0" "3" "6" "770" "0" "1933" "0" ""98028"" "47.7379" "-122.233" "2720" "8062"
I will let you take it from there.
EDIT — (10 Mar 2020 at 22:03)
For example, extracting the numeric values is straightforward:
Price = str2double(T1.price)
produces:
Price =
221900
538000
180000