[Tutor] tab separated file handling
Joel Goldstick
joel.goldstick at gmail.com
Wed Jun 13 08:22:33 EDT 2018
On Wed, Jun 13, 2018 at 6:03 AM, Niharika Jakhar <niharika1883 at gmail.com> wrote:
> hi everyone!
> I am working with a tsv file which has NA and empty values.
> I have used csv package to make a list of list of the data.
> I want to remove NA and empty values.
>
> This is what I wrote:
>
>
> #removes row with NA values
> for rows in self.dataline:
> for i in rows:
> if i == 'NA' or i == '':
> self.dataline.remove(rows)
>
>
> This is what the terminal says:
>
> self.dataline.remove(rows)
> ValueError: list.remove(x): x not in list
>
>
> This is how the file looks like:
>
> d23 87 9 NA 67 5 657 NA 76 8 87 78 90 800
> er 21 8 908 9008 9 7 5 46 3 5 757 7 5
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
for i in rows:
Gives you the complete line as a list. From there your test should be:
if "NA" in i:
# throw away this line
--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
More information about the Tutor
mailing list