pandas read excel openpyxl code example
Example 1: pandas excel python
import pandas as pd
movies = pd.read_excel('movies.xls')
movies.head(n=5)
movies.tail(n=5)
movies_sheet1 = pd.read_excel(excel_file, sheetname=0)
movies_sheet2 = pd.read_excel(excel_file, sheetname=1)
movies_sheet2 = pd.read_excel(excel_file, sheetname='name of third sheet')
sorted_by_gross = movies.sort_values(['Gross Earnings'], ascending=False)
movies.to_excel('output.xlsx')
Example 2: read excel file using pandas in python
import sqlite3
import pandas as pd
from sqlalchemy import create_engine
file = "location of Excel file..."
engine = create_engine('sqlite://', echo=False)
df = pd.read_excel(file, sheet_name=sheetname)
df.to_sql("test", engine, if_exists="replace", index=False)
results = engine.execute("Select * from test")
final = pd.DataFrame(results, columns=df.columns)