[BangPypers] Need help Extracting data properly in python
Baiju M
baiju.m.mail at gmail.com
Thu Feb 20 10:09:07 CET 2014
May be this one will be useful:
https://pypi.python.org/pypi/texttable
On Thu, Feb 20, 2014 at 2:26 PM, Abdul Muneer <abdulmuneer at gmail.com> wrote:
> There is an old python package which does it neatly
> http://www.astro.rug.nl/~breddels/python/tableio.html
>
> Regards,
> Abdul Muneer
>
> --
> Follow me on Twitter: @abdulmuneer <http://twitter.com/#%21/abdulmuneer>
>
>
> On Wed, Feb 19, 2014 at 5:59 PM, Kulkarni, Shreyas <shyran at gmail.com> wrote:
>
>> if this is a valid tab-seperated file, you could try parsing it using csv
>> module with dialect set to '\t' or 'excel-tab' maybe?
>>
>> shreyas
>>
>> On Feb 19, 2014, at 5:43 PM, "kamalakar06 ." <foxrun2005 at gmail.com> wrote:
>>
>> > I have a file like this(Tabular data) :
>> >
>> > 0 1 CEN/4 1.0000e3 3.000e3 4.000e-3
>> > 1.000e-3 3.000e3 5.000e3
>> >
>> > 11 2.000e3 3.000e4 6.000e3
>> > 1.000e4 1.000e4 1.000e5
>> >
>> > 12 1.00e4 1.000e5 1.000e6
>> > 2.00e4 2.000e5 1.000e4
>> >
>> > 0 2 CEN/4 1.0000e3 3.000e3 4.000e-3
>> > 1.000e-3 3.000e3 5.000e3
>> >
>> > 41 2.000e3 3.000e4 6.000e3
>> > 1.000e4 1.000e4 1.000e5
>> >
>> > 50 1.00e4 1.000e5 1.000e6
>> > 2.00e4 2.000e5 1.000e4
>> >
>> >
>> >
>> > I want to extract the data column wise. How do i do that
>> >
>> > My code is like this :
>> >
>> > import os
>> >
>> > f1=open('newdata1.txt','w')
>> > L = []
>> > for index, line in enumerate(open('Trial_1.txt','r')):
>> > #print index
>> > if index < 0: #skip first 5 lines
>> > continue
>> > else:
>> > line =line.split()
>> > L.append('%s\t%s\t %s\t %s\t%s\n' %(line[0],
>> > line[1],line[2],line[3],line[4]))
>> >
>> >
>> > f1.writelines(L)
>> >
>> > f1.close()
>> >
>> >
>> >
>> > Output looks like this:
>> >
>> > 0 1 CEN/4 1.0000e3 3.000e3
>> > 1.000e-3 3.000e3 5.000e3
>> >
>> >
>> > Now the code is not extracting the column data properly,since there is
>> tab
>> > space after first line . How to give tab space in python wherever space
>> is
>> > there to extract the data properly.Where to modify my code.
>> > _______________________________________________
>> > BangPypers mailing list
>> > BangPypers at python.org
>> > https://mail.python.org/mailman/listinfo/bangpypers
>>
>> _______________________________________________
>> BangPypers mailing list
>> BangPypers at python.org
>> https://mail.python.org/mailman/listinfo/bangpypers
>>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
More information about the BangPypers
mailing list