日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python高级玩法_python pandas to_excel 高级玩法

發布時間:2023/12/10 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python高级玩法_python pandas to_excel 高级玩法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

DataFrame.to_excel(self, excel_writer, sheet_name=‘Sheet1‘, na_rep=‘‘,

float_format=None, columns=None, header=True, index=True,

index_label=None, startrow=0, startcol=0, engine=None,

merge_cells=True, encoding=None, inf_rep=‘inf‘, verbose=True,

freeze_panes=None):

1、freeze_panes :固定行和列? ?int類型的 tuple

2、inf_rep? : python會出現最小值? 無限接近為0 的值為inf? ?inf_rep 為替換所有這個值

3、na_rep??:? inf_rep 為替換 np.nan 值

4、merge_cells :默認為True? ?為合并索引的

5、添加顏色 :

def style_apply(series, colors, **kwargs):

"""

:param series: 傳過來的數據是DataFrame中的一列 類型為pd.Series

:param colors: 內容是字典 其中key 為標題名 value 為顏色

:return:

"""

# print(series,type(series))

series_names = series.name

first_name = series_names[0]

# second_name = series_names[1] if len(series_names) > 1 else ‘‘

back_ground_list = list()

for cell in series:

back_ground = ‘‘

if isinstance(colors, str):

back_ground = ‘background-color: ‘ + colors

elif isinstance(colors, dict):

if first_name in colors:

back_ground = ‘background-color: ‘ + colors[first_name]

else:

logging.info(‘有問題‘)

back_ground_list.append(back_ground)

# print(len(back_ground_list))

return back_ground_list

# style_apply 為上面你的方法 colors 為顏色字典 目的是為了給不同的標題設置不同的顏色

# DataFrame 中的的 apply 默認傳參為 為 DataFrame 中的一列 Series

df = df.apply(style_apply, colors=colors, kwargs=kwargs)

總結

以上是生活随笔為你收集整理的python高级玩法_python pandas to_excel 高级玩法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。