I created a datframe df,
Value Change Direction
Date
2015-03-02 2117.38 NaN 0
2015-03-03 2107.79 -9.609864 0
2015-03-04 2098.59 -9.250000 0
2015-03-05 2101.04 2.510010 1
2015-03-06 2071.26 -29.780029 0
.
.
.
Now I am trying to replace the Direction value 0 by down arrow and 1 by up arrow. HTML code for down arrow is ಓ
解决方案
Try below code example:
import pandas as pd
Fruits = ('Apple', 'Mango', 'Grapes', 'Banana', 'orange')
Price = (100, 80, 50, 90, 60)
direction = (1, 0, 1, 1, 0)
df = pd.DataFrame({'Fruits': Fruits, 'Price': Price,'direction':direction})
df.direction.replace([1, 0],["↑", "↓"], inplace=True) #replace the values using html codes for up and down arrow.
html_df= df.to_html() #convert the df to html for better formatting view
html_df = html_df.replace("
↓"," ↓") # Remove extra tags and added red colour to down arrowhtml_df = html_df.replace("
↑"," ↑") # Remove extra tags and added green colour to up arrowprint(html_df) #print the df
Output file in browser: