Reputation: 161
I am trying to run this code
num = df_out.drop_duplicates(subset=['Name', 'No.']).groupby.(['Name']).size()
But when I do I get this error:
ValueError: not enough values to unpack (expected 2, got 0)
If we think about my dataframe(df_out) as an excel file I do have blank cells but no full column or full row is blank. I needed to skip the blank lines to run the code without changing the dataframe's structure.
Is this possible?
Thank you
Upvotes: 1
Views: 4241
Reputation: 2780
Consider using df.dropna()
. It is uses to remove rows that contains NA. See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html for more information.
At first, you probably want your "blank cells" to be converted to NA value, so they can be dropped by dropna()
. This can be done using various methods, notably df.replace(r'\s+', pandas.np.nan, regex=True)
. If your "blank cells" are all empty strings, or fixed strings equal to some value s
, you can directly use (first case) df.replace('', pandas.np.nan)
or (second case) df.replace(s, pandas.np.nan)
.
Upvotes: 3