Skip to content
Advertisement

Unsure how to set up for loops and if statements to filter the data that I want:

So I have a dataframe that kinda looks like this:

JavaScript

I want to search the dataframe and return exactly:

JavaScript

Cutting out the top and bottom. I was able to create a function that filtered out the “Titles” of each column of data. Now I am stuck trying to filter the data out cell by cell until I reach a “NaN” or blank in that column and then I want to move onto the next column. This is what I tried to get it to work:

JavaScript

I can’t get it to work because the function “insensitive compare” compares 2 strings and I get the error: “AttributeError: ‘float’ object has no attribute ‘lower'”. Which makes sense to me because I know I can’t do it, but I can’t figure out the logic otherwise. How do I start at a specific point in the column that is known by its index and column name. Then store the data until a “NaN” or blank is reached? Then I would want to go to the next column in the DataFrame and do the same thing.

EDIT** This function spits out the data in the cell I want, along with the row and column it is in:

JavaScript

Advertisement

Answer

Just an quick idea:

If you can assume that all valuable stuff starts with non-blank in the first character then you could get a new DF with valuable stuff:

JavaScript

(Blank lines need to have space in the first position for the above to work. )

Then if you could assume that the columns are separated by more than one space and that there are only single spaces in the data then something like:

JavaScript

would split into columns with the first row containing the column names.

Don’t have time to work it all out but thought I’d get you the idea in case it might help.

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