Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

extracting portion of the files

I have many files as follows(input.txt) and i want to extract portion of it and want to save to another text file

# 
# XXX
# YYY
# ZZZ
# AAAAAA
# AAAAAA
# AAAAAAA AAAAA
# CCCCC
# EEEEE
# EEEEE
# DDDDD
# A(MN)  S(MN/SN)  D(MN/WN) FPR(OO/WW)   ER   QW   RRRR   WWWW   QQQQQ   XXXXX
#
45.0300  1.4212  1.1300  1.7716  5.0000  4.0000  0.0400  0.0100  1.0020  1.5000
85.0300  1.9235  1.9974  1.0492  5.0000  4.0000  0.0400  0.0100  1.0020  1.5000
56.0300  1.1454  1.1255  1.0902  5.0000  4.0000  0.0400  0.0100  1.0020  1.5000
78.0300  1.9434  1.0089  1.0528  5.0000  4.0000  0.0400  0.0100  1.0020  1.5000

I want to extract below file from the above file

1.1300  
1.9974
1.1255
1.0089

I tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import pandas as pd
a=pd.read_csv("input.csv")
b=a.loc[12:15]

It doesnot work here. Hope experts may help me.Thanks.

>Solution :

A possible solution:

pd.read_csv('name_file.csv', comment='#', header=None, sep='\s+')[2]

Output:

0    1.1300
1    1.9974
2    1.1255
3    1.0089
Name: 2, dtype: float64
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading