I am trying to import a .dat file into a pandas dataframe for analysis.
A row in the .dat file contains 2 observations (year, population, and crime) and looks like this:
1960 179323175 3384200 1961 182992000 3488000
Marcin's solution was very helpful, however, I seem to have multiple observations on one row (as the .dat file is structured). Is there an equivalent to the @@ option in SAS, that allows pandas to specify the number of columns (or a better solution)? Thank you.
#importing .dat files into pandas
with open('Data_Exercises/CHAPTER4/DATA for Exercises 4.1 and 4.4.dat','r') as f:
#next(f) # this is what you would write to skip the first row.skip first row
df = pd.DataFrame((l.rstrip().split() for l in f))
print(df)