hbstha123
hbstha123

Reputation: 1636

How to drop a row with an empty cell from a pandas dataframe but with 0 value?

I have a dataframe which looks as follows: enter image description here

It is shown as empty. But when I check the value

df4.iloc[195]

it returns 0 of object type.

I want to remove it from my dataframe. I tried

df4.replace(0, np.nan, inplace=True)

But it is still present as an empty cell with 0 value. I also tried replacing "" with

np.nan

And I also tried using

regex=True

However, the problem seems to persist. Therefore, I cannot covert the pandas dataframe into a numeric type. What would be a good way to solve this issue?

.

Upvotes: 0

Views: 58

Answers (1)

BENY
BENY

Reputation: 323226

Try with convert to to_numeric

df4 = df4.apply(lambda x : pd.to_numeric(x, errors='coerce'))
df4 = df4.dropna()

Upvotes: 1

Related Questions