reading excel to a python data frame starting from row 5 and including headers

前端 未结 2 1730
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 05:24

how do I import excel data into a dataframe in python.

Basically the current excel workbook runs some vba on opening which refreshes a pivot table and does some othe

相关标签:
2条回答
  • 2020-12-05 05:42

    The accepted answer is old (as discussed in comments of the accepted answer). Now the preferred option is using pd.read_excel(). For example:

    df = pandas.read_excel('C:\Users\cb\Machine_Learning\cMap_Joins.xlsm'), skiprows=[0,1,2,3,4])
    
    0 讨论(0)
  • 2020-12-05 05:59

    You can use pandas' ExcelFile parse method to read Excel sheets, see io docs:

    xls = pd.ExcelFile('C:\Users\cb\Machine_Learning\cMap_Joins.xlsm')
    
    df = xls.parse('Sheet1', skiprows=4, index_col=None, na_values=['NA'])
    

    skiprows will ignore the first 4 rows (i.e. start at row index 4), and several other options.

    0 讨论(0)
提交回复
热议问题