Filling null values in multiple dataframe columns based on condition
in the end I solved the issue by adding an if clause where I use .loc only if column_values_to_update (which is a Set) is not empty.
I'm still baffled because my unit tests where column_values_to_update was empty still passed.....
oh well
So I wrote a function that fills any null values in 2 dataframe columns baded on a condition being met. I've written unit tests, they all work.
When running it on actual data, it sometimes leads to a ValueError: cannot set using a list-like indexer with a different length than the value
I'm confused because my unit tests pass. The code is essentially this:
df.loc[df['column'].isin(column_values_to_update), ['col2', 'col3']] = df[['col2', 'col3']].fillna(0)
It works when column_values_to_update is empty, it works when its full...yet when running on certain datasets, I get the ValueError and I'm not sure why....I've reset the index before getting to this point and no luck.
Anyone have any idea why sometimes this error can arise, and sometimes it doesn't? Let me know if you need more info...