python - How to read Txt file section by section by special marker using Pandas? -


i trying use pandas analyze text file output s structural analysis software. file has 24000+ lines can broken down sections, each of them starting $, example:

$ stories - in sequence top   story "platform"  height 51.9996    story "bulkhead"  height 117    story "emr"  height 124.9992    story "roof"  height 140.0004 similarto "41st fl"    $ grids   gridsystem "g1"  type "cartesian"  bubblesize 60    grid "g1"  label "g"  dir "x"  coord -1068 visible "yes"  bubbleloc "end"     grid "g1"  label "d"  dir "x"  coord -586 visible "yes"  bubbleloc "end"     grid "g1"  label "d.3"  dir "x"  coord -460 visible "yes"  bubbleloc "end"  

i can use pd.read_csv , specify skip_row parameter each of them, pretty repetitive , stupid when text file large. since output file quite formatted, there way parse text file sections headline of $..., , create pd.dataframe lines below $...?

i guess useful have specify number of txts:

marker = '$' txt1, txt2, txt3, txt4 = txt.split(marker) 

also, able specify regex rule marker?

you can make sections split function (and don't have specify number of txts). split function returns list object. each element of list represent section.

sections = txt.split("$") 

now can iterate through list.

for actual_section in sections:     print actual_section 

for more information read documentation split function here.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -