2016-09-27 162 views
-1

我想比較兩個CSV文件。如果在特定的單元格中存在差異(例如:第5行和第3列),則給該單元格賦予紅色。比較兩個csv文件和顏色代碼在csv中的差異

我可以能夠比較兩個文件,但無法獲得紅顏色的差值小區我都試過這個代碼

def compare(): 
try: 
    assert_frame_equal(df_sort_sas, df_sort_py) 
    return True 
except: # appeantly AssertionError doesn't catch all 
    return False 
compare() 

我想這樣的輸出: 這裏紅色細胞是指特定的值不與第一個CSV細胞等於

enter image description here

+1

您要添加的顏色爲「CSV」文件中的電池?這不可能。 – sisanared

回答

0

您不能設置在CSV文件中的顏色。希望你能做的就是做在Excel中: 看一看這兩個問題:How to change background color of excel cell with python xlwt library?Setting a cell's fill RGB color with pywin32 in excel

要summen了answers

from xlwt import Workbook 
import xlwt 
book = Workbook() 
sheet1 = book.add_sheet('Sheet 1') 
book.add_sheet('Sheet 2') 
for i in range(0, 100): 
    st = xlwt.easyxf('pattern: pattern solid;') 
    st.pattern.pattern_fore_colour = i 
    sheet1.write(i % 24, i/24, 'Test text',st) 
book.save('simple.xls') 

here

def rgb_to_hex(rgb): 
    strValue = '%02x%02x%02x' % rgb 
    iValue = int(strValue, 16) 
    return iValue 

xl.ActiveSheet.Cells(row, column).interior.color = rgb_to_hex((255,255,0)) 

積分給作者不是我

相關問題