3

I am reading data from a binary .out file using a python module "SWMMToolbox." The command to read the infilration time series for RG1 from the file.out is as follows:

x = !swmmtoolbox extract 'file.out' subcatchment,RG1,Infiltration_loss

See link for details about swmmtoolbox.

The data type of 'x' is a 'IPython.utils.text.SList' The data looks like this: enter image description here

I would like to import this Slist into pandas, but am having trouble. I want to get the datetime string as one column and the value after the comma as another. However, when I use

df = pd.DataFrame(data=x)

I get the following: enter image description here

I also tried to use

df = pd.DataFrame.from_records(x)

but get this:

enter image description here

I tried to use pd.read_csv, but I couldn't get it to work since 'x' is a variable and not a file.

Any suggestions are much appreciated.

Community
  • 1
  • 1
LCook
  • 97
  • 1
  • 1
  • 7
  • df = pd.DataFrame(data=x).str.split(',',expand=True) – BENY Aug 06 '18 at 18:50
  • Great suggestion! I got the following error: AttributeError: 'DataFrame' object has no attribute 'str' – LCook Aug 06 '18 at 20:13
  • 1
    pd.DataFrame(data=x)[0].str.split(',',expand=True) – BENY Aug 06 '18 at 20:14
  • This worked: df[0].str.split(',',expand=True). Thanks for your help! – LCook Aug 06 '18 at 20:22
  • @LCook What exactly worked, can you please write the entire line? – Eight Rice Feb 26 '20 at 20:46
  • 1
    @AndreiȚăranu, for example, slist = !swmmtoolbox extract $path_file subcatchment,R1,Rainfall; df = pd.DataFrame(data=slist); df = df[0].str.split(',',expand=True); df = df.rename(columns=df.iloc[0]) – LCook Feb 28 '20 at 12:08
  • Trying to do the same thing, @LCook but getting an error. df[0] returns an error as well. I am running py3.8. Did pandas change how this works since you were successful perhaps? df.to_string works but I unable t then split. – RossV May 07 '21 at 15:43

0 Answers0