Skip to content
Advertisement

Remove empty lists in csv file in python

So I have a csv file called result and I’m getting this:

JavaScript

when I just want this:

JavaScript

as in without the empty lists.

How would I go about doing this? I tried to do

JavaScript

and I tried this:

JavaScript

and I tried this:

JavaScript

but none of them worked.

Advertisement

Answer

EDITED (after collecting more information):

I do think that attempting to work around bad data is not worth the trouble, but to answer the question literally would require comething like this:

JavaScript

this will print the filtered list to stdout; you can then capture that output and save is as a new csv file. In any Unix-based OS you can just redirect the stdout to a file, properly named.

==== ORIGINAL =====

It’s difficult to understand what exactly you are trying to do in your code samples. For example, this line:

JavaScript

will write every character in the string (which looks like a file name, but who cares) into a file – whatever is attached to the writer object (results.csv in your sample #1 above).

Are you trying to write a collection of objects to a csv file?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement