I want to drop those rows in a dataframe that have value '0' in the column 'candidate'. Some of my dataframes only have value '0' in this column. I expected that in this case I will get an empty dataframe, but instead I get the following warning and the unchanged dataframe. How can I get an empty dataframe in this case? Or prevent returning an unchanged dataframe?
Warning message:
C:\Users\User\Anaconda3\lib\site-packages\pandas\core\ops\array_ops.py:253: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison res_values = method(rvalues)
My code:
with open(filename, encoding='utf-8') as file:
df = pd.read_csv(file, sep=',')
df.drop(df.index[(df['candidate'] == '0')], inplace=True)
print(df)
post id ... candidate
0 1 ... 0
1 1 ... 0
2 1 ... 0
3 1 ... 0
4 1 ... 0
.. ... ... ...
182 10 ... 0
183 10 ... 0
184 10 ... 0
185 10 ... 0
186 10 ... 0
[187 rows x 4 columns]