Search This Blog

2023/10/01

Python:read xlsx

 import pandas as pd

# read by default 1st sheet of an excel file
df = pd.read_excel('name.xlsx')
rows = len(df.index)
cols = len(df.columns)

header = list(df.columns.values)

for head in range(len(header)):
print(header[head] + " ",end=" ")

print()

for row in range(rows):
for col in range(cols):
print(df.iat[row, col] + " ",end="")
print()



# pip install pandas
# pip install openpyxl

No comments:

Post a Comment