Extract columns from Excel using Python

前端 未结 3 1834
猫巷女王i
猫巷女王i 2020-12-18 13:05

I have an Excel file with the ff: row/col structure

ID   English   Spanish   French
 1   Hello     Hilo      Halu
 2   Hi        Hye       Ghi
 3   Bus               


        
3条回答
  •  攒了一身酷
    2020-12-18 13:17

    import xlrd
    
    sh = xlrd.open_workbook('input.xls').sheet_by_index(0)
    english = open("english.txt", 'w')
    spanish = open("spanish.txt", 'w')
    french = open("french.txt", 'w')
    try:
        for rownum in range(sh.nrows):
            english.write(str(rownum)+ " = " +str(sh.cell(rownum, 0).value)+"\n")
            spanish.write(str(rownum)+ " = " +str(sh.cell(rownum, 1).value)+"\n")
            french.write(str(rownum)+ " = " +str(sh.cell(rownum, 2).value)+"\n")
    finally:
        english.close()
        spanish.close()
        french.close()
    

提交回复
热议问题