I am trying to read in a csv file into a pandas dataframe and then set the column to the specified columns in columns=[ ... ]
Would anyone now why its not reading in all of my data? p
fp = '/Users/USERNAME/Development/file.csv'
file1 = open(fp, 'rb').read()
reader = pd.DataFrame.from_csv(fp, index_col=False, sep=',')
df = pd.DataFrame(reader, columns=['VIN', 'Reg City','First Name','Last Name','MGVW','Nat Flt Ind','MGVW',
'Reg Name','Phone', 'Unnamed: 8','ZIP','VC','VType',
'Reg Voc', 'Make','Veh Model', 'E Mfr','Engine Model',
'CY2010', 'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015',
'Std Cnt',])
#reader.head(1)
df.head(1)
VIN Reg City First Name Last Name MGVW Nat Flt Ind MGVW Reg Name Phone Unnamed: 8 ... Veh Model E Mfr Engine Model CY2010 CY2011 CY2012 CY2013 CY2014 CY2015 Std Cnt 0 NaN KANSAS NaN NaN NaN N NaN ACE PIPE CLNG INC NaN NaN ... NaN NaN NaN 0 1
Just do df = pd.read_csv('/Users/USERNAME/Development/file.csv')
to load your CSV file. If I am not mistaken, from_csv
as been replaced by read_csv
.
Here is a version to load only certain colunns. set usecols
in pd.read_csv()
.
import pandas as pd
fp = '/Users/USERNAME/Development/file.csv'
usecols = ['VIN', 'Reg City','First Name','Last Name','MGVW','Nat Flt Ind','MGVW',
'Reg Name','Phone', 'Unnamed: 8','ZIP','VC','VType',
'Reg Voc', 'Make','Veh Model', 'E Mfr','Engine Model',
'CY2010', 'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015',
'Std Cnt']
df = pd.read_csv(fp, usecols=usecols, sep=',')
print df.head()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.