Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html中的Python货币样式问题_Python_Html_Pandas - Fatal编程技术网

html中的Python货币样式问题

html中的Python货币样式问题,python,html,pandas,Python,Html,Pandas,我试图添加卢比样式附加值使用巴别塔 我使用babel来设计货币样式,但是在将数据框转换为html之后 我没有得到卢比样式的字体,但一些垃圾像任何解决方案 from babel.numbers import format_currency lambda x: format_currency(x, 'INR', locale='en_IN') 我无法访问您的数据帧代码,因此我只能根据您当前的问题提供答案 请注意:这是我第一次真正尝试使用熊猫数据帧 import pandas as pd from

我试图添加卢比样式附加值使用巴别塔 我使用babel来设计货币样式,但是在将数据框转换为html之后 我没有得到卢比样式的字体,但一些垃圾像任何解决方案

from babel.numbers import format_currency
lambda x: format_currency(x, 'INR', locale='en_IN')

我无法访问您的数据帧代码,因此我只能根据您当前的问题提供答案

请注意:这是我第一次真正尝试使用熊猫数据帧

import pandas as pd
from babel.numbers import format_currency

indian_rupee = lambda x: format_currency(x, 'INR', locale='en_IN')

print (indian_rupee(450000))
# output
₹ 4,50,000.00

number_of_rupees = indian_rupee(450000)

df = pd.DataFrame({'rupees':[number_of_rupees]})
raw_html = df.to_html()

print (raw_html)
# output
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
     <th></th>
     <th>rupees</th>
   </tr>
 </thead>
   <tbody>
    <tr>
     <th>0</th>
     <td>₹ 4,50,000.00</td>
   </tr>
 </tbody>
将熊猫作为pd导入
从babel.numbers导入格式\货币
印度卢比=lambda x:格式为货币(x,'INR',locale='en_IN')
印刷品(印度卢比(450000))
#输出
₹ 4,50,000.00
卢比数量=印度卢比(450000)
df=pd.DataFrame({'rupes':[numberofrupes]})
原始html=df.to_html()
打印(原始html)
#输出
卢比
0
₹ 4,50,000.00

下面是另一个例子:

import pandas as pd
from babel.numbers import format_currency

indian_rupee = lambda x: format_currency(x, 'INR', locale='en_IN')

convert_to_rupees = ['12000', '450000', '2000']

rupee_amounts = []

for item in convert_to_rupees:
  number_of_rupees = indian_rupee(item)
  rupee_amounts.append(number_of_rupees)

se = pd.Series(rupee_amounts)

df = pd.DataFrame()
df['rupees'] = se.values
raw_html = df.to_html()

print (raw_html)
# output 
<table border="1" class="dataframe">
 <thead>
   <tr style="text-align: right;">
    <th></th>
     <th>rupees</th>
   </tr>
 </thead>
 <tbody>
  <tr>
  <th>0</th>
  <td>₹ 12,000.00</td>
   </tr>
   <tr>
     <th>1</th>
     <td>₹ 4,50,000.00</td>
   </tr>
   <tr>
    <th>2</th>
    <td>₹ 2,000.00</td>
   </tr>
 </tbody>
</table>
将熊猫作为pd导入
从babel.numbers导入格式\货币
印度卢比=lambda x:格式为货币(x,'INR',locale='en_IN')
将卢比换算为卢比=['12000','450000','2000']
卢比金额=[]
对于单位为卢比的项目:
卢比数量=印度卢比(项目)
卢比金额。追加(卢比数量)
se=pd.系列(卢比金额)
df=pd.DataFrame()
df[‘卢比’]=se.值
原始html=df.to_html()
打印(原始html)
#输出
卢比
0
₹ 12,000.00
1.
₹ 4,50,000.00
2.
₹ 2,000.00

lambda x:format_currency(x,'INR',locale='en_IN')如何。替换(u'\xa0',u')然后
到_html
感谢ans,但问题仍然没有解决。我仍然得到像“2,82015.00”这样的输出。我提供的答案是一个字符串(450000)通过format\u currency运行它,并将输出添加到数据帧,并将其转换为\u html。html表显示了INR的正确符号。因此,我假设您的pandas代码中存在另一个问题,您没有共享该问题,这导致了格式问题。请共享一些其他代码没有其他问题,实际上我的系统上没有安装导致问题的“en_IN”的区域设置。谢谢你的回答。无论是谁提供了-1,请你详细说明原因,以便我改进我的答案?