第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

帶有 Pandas 數(shù)據(jù)框千位分隔符的 XlsxWriter

帶有 Pandas 數(shù)據(jù)框千位分隔符的 XlsxWriter

拉風(fēng)的咖菲貓 2022-06-02 15:42:00
據(jù)我所知,Xlsxwriter 可能是用千位分隔符格式化我的數(shù)字的最佳軟件包。我已經(jīng)多次閱讀 xlsxwriter 文檔,仍然很困惑,我認(rèn)為其他人可能有同樣的問(wèn)題,因此我在這里發(fā)布我的問(wèn)題。我有一個(gè)熊貓數(shù)據(jù)框 DF_T_1_EQUITY_CHANGE_Summary_ADE,我想將它們導(dǎo)出到 excel 并使用格式化千位分隔符。Row Labels               objectSum of EQUITY_CHANGE    float64Sum of TRUE_PROFIT      float64Sum of total_cost       float64Sum of FOREX VOL        float64Sum of BULLION VOL      float64Oil                     float64Sum of CFD VOL           objectSum of BITCOIN VOL       objectSum of DEPOSIT          float64Sum of WITHDRAW         float64Sum of IN/OUT           float64dtype: object數(shù)據(jù)框 DF_T_1_EQUITY_CHANGE_Summary_ADE 很清楚,除了第一列行標(biāo)簽是對(duì)象,其他都是數(shù)字。因此,我使用 xlsxwriter 將數(shù)據(jù)框?qū)懭?excel:import xlsxwriter num_fmt = workbook.add_format({'num_format': '#,###'}) #set the separator I wantwriter = pd.ExcelWriter('ADE_CN.xlsx', engine='xlsxwriter')DF_T_1_EQUITY_CHANGE_Summary_ADE.to_excel(writer, sheet_name='Sheet1')workbook=writer.bookworksheet = writer.sheets['Sheet1']worksheet.set_column('C:M', None, num_fmt)writer.save()但是,我沒(méi)有得到千位分隔符,excel中的結(jié)果如下:    Row Labels  Sum of EQUITY_CHANGE    Sum of TRUE_PROFIT  Sum of total_cost   Sum of FOREX VOL    Sum of BULLION VOL  Oil Sum of CFD VOL  Sum of BITCOIN VOL  Sum of DEPOSIT  Sum of WITHDRAW Sum of IN/OUT0   ADE A BOOK USD  778.17  517.36  375.9   37.79   0.33    0   0   0   1555.95 0   1555.951   ADE B BOOK USD  6525.51 403.01  529.65  35.43   14.3    0   0   0   500 -2712.48    -2212.482   ADE A BOOK AUD  537.7   189.63  147 12.25   0   0   0   0   0   0   03   ADE B BOOK AUD  -22235.71   7363.14 224.18  2.69    9.16    0.2 0   0   5000    -103    4897有人可以提供解決方案,非常感謝。
查看完整描述

1 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

它應(yīng)該工作。在獲得對(duì)工作簿對(duì)象的引用后,您需要add_format()稍后在代碼中移動(dòng)它。這是一個(gè)例子:


import pandas as pd



# Create a Pandas dataframe from some data.

df = pd.DataFrame({'Data': [1234.56, 234.56, 5678.92]})


# Create a Pandas Excel writer using XlsxWriter as the engine.

writer = pd.ExcelWriter('pandas.xlsx', engine='xlsxwriter')


# Convert the dataframe to an XlsxWriter Excel object.

df.to_excel(writer, sheet_name='Sheet1')


# Get the xlsxwriter workbook and worksheet objects.

workbook  = writer.book

worksheet = writer.sheets['Sheet1']


# Set a currency number format for a column.

num_format = workbook.add_format({'num_format': '#,###'})

worksheet.set_column('B:B', None, num_format)


# Close the Pandas Excel writer and output the Excel file.

writer.save()


輸出:

http://img1.sycdn.imooc.com//629869e20001324503530236.jpg

查看完整回答
反對(duì) 回復(fù) 2022-06-02
  • 1 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)