I had this working, and now I changed "something" and it doesn't work any more. I have a table in Excel that I'm reading into a df. That works as expected. I read it in, and then I filter it so I only have the rows of data that match a specific criteria. Here's the code:
df = excel_range_upper_left.options(pd.DataFrame, expand='table', header=1, index=False).value print(f'Check for missings') for c in df.columns: count = df[c].isnull().sum() print(f'Col {c} has {count} missing values') print(f'Done checking for missings') df = df[df["Phase"].str.contains('2')] #, na=False)]The for loop cycles through the df columns looking for missing values. They all come back as 0 missing values.
Then I execute the last statement, which should (I think) simply filter the df into a new df (of the same name) that has to have a string value '2' in the 'Phase' column. And that where it errors out with the Cannot mask... error.
My guess is that there is still a missing value somewhere in the table, but I've exhausted my ability to find it (I also tried the following - but it results in the same thing as the original df and still errors out:
print(f'{exer_df.dropna(axis=1)}')If I change the filter line to the following so it includes the na=False option, everything works. But I don't know why...
exer_df = exer_df[exer_df["Phase"].str.contains('2', na=False)]Anyone have any insight and help?
For completeness, here are the results from the for loop and then the error:
Check for missingsCol Type as 0 missing valuesCol Sub-Type as 0 missing valuesCol Phase as 0 missing valuesCol Body Parts as 0 missing valuesCol Sets as 0 missing valuesCol Reps as 0 missing valuesCol Tempo as 0 missing valuesCol Intensity as 0 missing valuesCol Rest Period as 0 missing valuesCol Exercise as 0 missing valuesCol Prim Mover as 0 missing valuesDone checking for miossingsTraceback (most recent call last): File "c:/Users/kirby/OneDrive/Beating Old Age Book/Blog Page Text/nutrition/calculations/plan_creator.py", line 271, in <module> mcp() File "c:/Users/kirby/OneDrive/Beating Old Age Book/Blog Page Text/nutrition/calculations/plan_creator.py", line 188, in mcp exer_df = exer_df[exer_df["Phase"].str.contains('2')] #, na=False)] File "C:\Users\kirby\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", line 3014, in __getitem__ if com.is_bool_indexer(key): File "C:\Users\kirby\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\common.py", line 114, in is_bool_indexer raise ValueError(na_msg)ValueError: Cannot mask with non-boolean array containing NA / NaN values