Skip to content
Advertisement

Function to read csv string

This question is duplicate of a now deleted earlier question now edited as per the comments provided in the original.

I am trying to create a function which takes a string input in CSV format. For example "id,name,age,scoren1,Jack,NULL,12n17,Betty,28,11".

It should return the follow table:

id name age score
1 Jack NULL 12
17 Betty 28 11

It should also remove the defective rows. A defective row is when it has value NULL in all capital letters — any other characters like (0 to 9 or a to z or A to Z) are acceptable.

The final output from the above input string should be:

id name age score
17 Betty 28 11

Here is my code using pandas and csv packages. I need to create this without using any of these packages.

JavaScript

Advertisement

Answer

Here’s how to do what you say you want. Your description of the desired “table” output is somewhat vague, so I made my best guess.

JavaScript

Plain text sample output:

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