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

How i can take the integer in string from a row in csv file to python?

Hy guys my teacher has assing me to get the integer from a row string in one column. This all thing is going to be by read a csv file with the help from python.So my terminal dosen’t hit but i dont get nothing as a guide problem, i want from every row to take the integer and print them.

Here is my code :

import pandas as pd

tx = [ "T4.csv" ]


for name_csv in tx : 
  df = pd.read_csv( name_csv, names=["A"])
  for row in df: 
   if row == ('NSIT ,A: ,'):
     # i dont know how to use the split for to take the integer and print them !!!!
        print("A",row)
   else 
     # i dont know how to use the split for to take the integer and print them !!!!
     print("B",row)

Also here is and what it have the the csv file :(i have the just them all in the column A)

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

 NSIT ,A: ,-213

 NSIT ,A: ,-43652

 NSIT ,B: ,-39

 NSIT ,A: ,-2

 NSIT ,B: ,-46

At the end i have put my try on python, i hope you guys to understand the problem i have.

>Solution :

Read the file one line at a time. Split each line on comma. Print the last item in the resulting list.

with open('T4.csv') as data:
    for line in data:
        tokens = line.split(',')
        if len(tokens) > 0: # check for blank line(s)
            print(tokens[-1])
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