python可视化双向箭头_Python向数据框显示HTML箭头

本文展示了如何将Python DataFrame中的数值替换为HTML代码表示的上下箭头,以实现数据可视化的增强效果。通过使用pandas的replace方法和HTML箭头代码,将Direction列的0替换为向下箭头,1替换为向上箭头,并最终将DataFrame转换为HTML格式,以获得更清晰的展示。
摘要由CSDN通过智能技术生成

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 arrow

html_df = html_df.replace("

↑"," ") # Remove extra tags and added green colour to up arrow

print(html_df) #print the df

Output file in browser:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值