Extract columns from Excel using Python

前端 未结 3 1869
猫巷女王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:19

    Use pandas:

    In [1]: import pandas as pd
    
    In [2]: df = pd.ExcelFile('test.xls').parse('Sheet1', index_col=0) # reads file
    
    In [3]: df.index = df.index.map(int)
    
    In [4]: for col in df.columns:
       ...:     column = df[col]
       ...:     column.to_csv(column.name, sep='=')  # writes each column to a file                                                    
       ...:                                          # with filename == column name
    
    In [5]: !cat English  # English file content
    1=Hello
    2=Hi
    3=Bus
    

提交回复
热议问题