1

I have a dataframe column whose curren ...

1 Answer 1

3

Use pd.to_numeric with errors='coerce' parameter:

df['Sno'] = pd.to_numeric(df['Sno'], errors='coerce')
df = df[df['Sno'].notna()].astype({'Sno': int})

Output:

>>> df
   Sno  test
0   12     5
1   14     5
2   15     7
3   16     8
4   17     9
Sign up to request clarification or add additional context in comments.

2 Comments

I obtain the following error on running the first line: raise IntCastingNaNError( pandas.errors.IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer
Yes, you can do on any other column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.