Search code examples
pythoncsvxlsxfile-readreader

What's the equivalent of reader = csv.reader(...) for xlsx sheets?


I have a script with

path=r"mypath\myfile.xlsx"

with open(path) as f:
        reader = csv.reader(f)

but it won't work because the code is trying to open an xlsx file with a module made for csv files.

So, does an expression equivalent for xlsx files exist?


Solution

  • The equivalent of the highlighted code for xlsx sheets is:

    path=r"mypath\myfile.xlsx"
    
    import pandas as pd
    
    with open(path) as f:
            reader = pd.read_excel(f)