pandas - How to read a large text file in Python? -


i using enthought canopy (a set of many different python library packages e.g. numpy, pandas,etc) data analysis. trying read text file , create dataframe out of it. text file has 1180598 rows , 18 columns. columns have numbers in them. wrote following code reading , naming data columns:

from pandas import dataframe, read_csv import matplotlib.pyplot plt  import pandas pd  print 'pandas version ' + pd.__version__ pandas version 0.12.0  location=r'c:\umair\directed studies\us-101 data\main data\us-101-main-data\vehicle-trajectory-data\0750am-0805am\tra.txt'  df=read_csv(location, names=['vehicle id','frame id','total frames','global time','local x','local y','global x','global y','vehicle length','vehicle width','vehicle class','vehicle velocity','vehicle acceleration','lane identification','preceding vehicle','following vehicle','spacing','headway'])  df out[41]:  <class 'pandas.core.frame.dataframe'> int64index: 1180598 entries, 0 1180597 data columns (total 18 columns): vehicle id              1180598  non-null values frame id                0  non-null values total frames            0  non-null values global time             0  non-null values local x                 0  non-null values local y                 0  non-null values global x                0  non-null values global y                0  non-null values vehicle length          0  non-null values vehicle width           0  non-null values vehicle class           0  non-null values vehicle velocity        0  non-null values vehicle acceleration    0  non-null values lane identification     0  non-null values preceding vehicle       0  non-null values following vehicle       0  non-null values spacing                 0  non-null values headway                 0  non-null values dtypes: float64(17), object(1)  

as can see out[41], file read have 1 column only. should let python know file has 18 columns read way meant be?

this import dataset correctly:

df = pd.read_csv(location, names=names, header=none, delim_whitespace=true) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -