zoukankan      html  css  js  c++  java
  • example

    import pandas as pd
    import numpy as np
    import os,sys
    
    df = pd.read_excel("C:\Users\ryanzhang\Desktop\template.xlsx")
    a = df.columns
    b = pd.DataFrame(a,a)
    c = b.T
    d = c.append(df)
    
    def highlight_max(s):
        if s.name == 0:
        #print(['background-color: yellow' if v else '' for v in is_max])
            return ['background-color: yellow']*len(s)
        else:
            return ['']*len(s)
        
    one = df.style.set_properties(**{'border-style': 'solid','border-width':'1px','text-align':'left'})
    two = one.apply(highlight_max,axis=1)
    two.to_excel("C:\Users\ryanzhang\Desktop\test.xlsx",header=False, index=False,)
    import pandas as pd
    a = [["ryan","job","can"],["good","you","me"],["ryan","hello","how"],["any","each","where"]]
    name = ["one","two","three"]
    index = ["four","five","six","seven"]
    b = pd.DataFrame(a,index=index,columns=name)
    print(b,"
    ")
    def need_group(index):
        if b.loc[index]["one"] =="ryan":
            return 1
        elif b.loc[index]["one"] =="good":
            return 1
        elif b.loc[index]["one"] =="any":
            return 3
    
    c = b.groupby(need_group)
    for i,j in c:
        print(i,"
    ",j)    
  • 相关阅读:
    绘制八卦阵
    绘制奥运五环
    绘制渐变的圆
    实验报告
    大学排名
    第一条爬虫
    自己的第一个网页
    科学计算与可视化
    类和正则表达(自动更正 代数运算)
    预测比赛
  • 原文地址:https://www.cnblogs.com/windyrainy/p/10999377.html
Copyright © 2011-2022 走看看