Python Pandas dataframe reading exact specified range in an excel sheet

后端 未结 3 1172
北海茫月
北海茫月 2020-12-28 19:17

I have a lot of different table (and other unstructured data in an excel sheet) .. I need to create a dataframe out of range \'A3:D20\' from \'Sheet2\' of Excel sheet \'data

3条回答
  •  [愿得一人]
    2020-12-28 19:55

    Use the following arguments from pandas read_excel documentation:

    • skiprows : list-like
      • Rows to skip at the beginning (0-indexed)
    • parse_cols : int or list, default None
      • If None then parse all columns,
      • If int then indicates last column to be parsed
      • If list of ints then indicates list of column numbers to be parsed
      • If string then indicates comma separated list of column names and column ranges (e.g. “A:E” or “A,C,E:F”)

    I imagine the call will look like:

    df = read_excel(filename, 'Sheet2', skiprows = 2, parse_cols = 'A:D')
    

提交回复
热议问题