2

I have a dataframe, some of the cell in the dataframe have 0 , how to replace all the 0 with ' ' ?

final = final.replace(0, '')

This code not able run...Anyone can share me idea?

9
  • 2
    The code snippet you posted should've worked but it really depends on your actual data, please post raw data and code to reproduce your actual df Commented Apr 27, 2017 at 9:36
  • What is final.dtypes? Commented Apr 27, 2017 at 9:37
  • So maybe need final = final.replace('0', '') Commented Apr 27, 2017 at 9:38
  • dtype is object Commented Apr 27, 2017 at 9:40
  • So does jezrael's suggestion work? Commented Apr 27, 2017 at 9:41

1 Answer 1

5

I think you need:

final = final.replace(0, np.nan)
              .style.apply(color, axis=None)
              .set_table_attributes('border="" class = "dataframe table table-hover table-bordered"')
              .set_precision(10)
              .render() 
Sign up to request clarification or add additional context in comments.

8 Comments

but my 0 is a number
it is in int type
All values are int? Or floats?
some are float some are integer
What return df.dtypes ?
|

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.