Python Pandas html output from DataFrame & using MySQL sample table as source by to_html()

preview_player
Показать описание
We can create html table output or file by using data from Pandas DataFrame. We will first create one Pandas DataFrame by using some sample data.

import pandas as pd
my_dict={
'NAME':['Ravi','Raju','Alex'],
'ID':[1,2,3],'MATH':[30,40,50],
'ENGLISH':[20,30,40]
}
df = pd.DataFrame(data=my_dict)

After creating the DataFrame we used to_html() to create html tags out of the data
This output we can use to create file to store the string.
We can add different options while generating the html tags . One important options is columns(), col_space, header, index, justify , max_width etc.

From MySQL database using read_sql()
We can connect to MySQL database by using SQLAlchemy engine and after connection we will create our DataFrame by using data from sample table by using read_sql.
from sqlalchemy import create_engine
sql="SELECT * FROM student LIMIT 0,10"
Here 10 rows of data from the student table is taken and displayed as string .
Excel or CSV file to string
From excel file we can create string by first creating the dataframe by reading the excel file by using the method read_excel()

Similarly we can read csv file and generate JSON string

#pandas_to_html #dataframetohtml #pandashtml #plus2net #pandas #datascience #pandastutorials
Рекомендации по теме
Комментарии
Автор

Can you explain me how we format these tables? Ive just built an application doing this but my boss want the headers in dark blue, bold and with the font segoe ui 16 while the rows are with font segue ui and size 12

joaogabriel