1

I have a text file that looks like this:

1
    SWAT May 20 2015    VER 2015/Rev 637                                                                 0/ 0/   0      0: 0: 0

    General Input/Output section (file.cio):                                        
    3/23/2016 12:00:00 AM ARCGIS-SWAT interface AV                                  



           RES  MON    VOLUMEm3  FLOW_INcms FLOW_OUTcms    PRECIPm3      EVAPm3   SEEPAGEm3  SED_INtons SED_OUTtons SED_CONCppm   ORGN_INkg  ORGN_OUTkg RES_ORGNppm   ORGP_INkg  ORGP_OUTkg RES_ORGPppm    NO3_INkg   NO3_OUTkg  RES_NO3ppm    NO2_INkg   NO2_OUTkg  RES_NO2ppm    NH3_INkg   NH3_OUTkg  RES_NH3ppm   MINP_INkg  MINP_OUTkg RES_MINPppm   CHLA_INkg  CHLA_OUTkgSECCHIDEPTHm   PEST_INmg  REACTPSTmg    VOLPSTmg  SETTLPSTmgRESUSP_PSTmgDIFFUSEPSTmgREACBEDPSTmg   BURYPSTmg  PEST_OUTmgPSTCNCWmg/m3PSTCNCBmg/m3
RES          1    1  0.6062E+07  0.6285E+00  0.0000E+00  0.8282E+05  0.6664E+05  0.0000E+00  0.1900E+02  0.0000E+00  0.6782E+02  0.3444E+04  0.0000E+00  0.1546E-01  0.6055E+03  0.0000E+00  0.1315E-02  0.1358E+04  0.0000E+00  0.6315E-02  0.1422E+02  0.0000E+00  0.9853E-04  0.1722E+04  0.0000E+00  0.9114E-02  0.5736E+03  0.0000E+00  0.1543E-02  0.0000E+00  0.0000E+00  0.3960E+01  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00

I tried code with different separators, but always my resulting dataframe has one column only:

> df=pd.read_csv('output.rsv', skiprows=5, sep='\t', engine='python')

What I want to do with this data is just to divide this text into columns like this:

RES MON VOLUMEm3
1   1   1000
2   1   1000
...
Sergey Gulbin
  • 301
  • 1
  • 4
  • 15
  • An idea: I'd try to cut off the whole header with `skiprows = 9, header = None, sep='\s+'` and maybe `nrows = some_small_number` for a small chunk first. Hopefully separators are not some strange unicode characters. – ptrj Apr 16 '16 at 04:13

2 Answers2

0
pd.read_csv(filename, skiprows=5, skipinitialspace=True, sep=' ')

You may need sep='\t' depending on how your text file was encoded.

This worked for me when copying your data above and pasting into a .txt file which I then read.

Alexander
  • 105,104
  • 32
  • 201
  • 196
  • Yes, I can read the file, but the dataframe has dimensions (1300,1), but I need dataframe with multiple columns (1300,31). – Sergey Gulbin Apr 12 '16 at 01:40
0

The \s+ delimiter would work :

df = pd.read_csv(os.path.join(maindir, 'EDMA_1_rcp26_2025_1_output.rsv'),\
skiprows = 9, delimiter = r'\s+', header = None)

Pretty simple, actually.

Sergey Gulbin
  • 301
  • 1
  • 4
  • 15