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

Reading number between characters from a csv file python

I have this file with this data:

0,901,48.892795924112306,2.391225227186182,20
1,903,48.83713368945151,2.374340554605615,20
2,904,48.85213620522547,2.301961227213259,30
3,905,48.83966087889425,2.382472269083633,20
4,906,48.876419813641114,2.358630064544601,20

I want to print the number between 2 commas (,) alone on a new line but without the first column and the last column

example of the desired output:

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

901
48.892795924112306
2.391225227186182
903
48.83713368945151
2.374340554605615

and so on…

>Solution :

Here a sample:

csv = """0,901,48.892795924112306,2.391225227186182,20
1,903,48.83713368945151,2.374340554605615,20
2,904,48.85213620522547,2.301961227213259,30
3,905,48.83966087889425,2.382472269083633,20
4,906,48.876419813641114,2.358630064544601,20"""

for row in csv.split():
    print('\n'.join(row.split(',')[1:-1])) 

You should open the file and read each line (task for you).

row.split(',')[1:-1] slice the row by omitting the 1st and last entries which are those surrounded by the ,

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