Pandas is one of the data manipulation libraries in Python, and is specifically designed for data analysis and manipulation. It offers different data structures and built-in methods to manipulate numerical data or tables.
to_html() method from
pandas.DataFrame module is used to convert a DataFrame into an HTML table.
DataFrame.to_html(buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', max_rows=None, max_cols=None, border=None, encoding=None)
It takes the below-mentioned parameter values.
buf: This is a string or StringIO-like object to write the output.
columns: This is a subset of columns that are going to write. The default is
None, which means write all.
col_space: This is an integer or list-like object. It shows the column space as a pixel value. By default, it's
header: This boolean value shows whether the column names have to be specified or not. Its default value is
index: This is the boolean value, which shows whether to show the index or not. Its default value is
na_rep: This replaces
NaN, that is, the string representation.
max_rows: This is the integer value that represents the total number of rows to print on the console. Its default value is
max_cols: This is the integer value that represents the total number of columns that are going to print on the console. Its default value is
show_dimensions: When set to
True, this will print dimensions of DataFrame. Its default value is
border: This is the
border=borderattribute to apply on table tag. Its default value is
encoding: It shows the data encoding scheme.
If argument value
None, it will return converted HTML as a string otherwise
# import DataFrame import pandas as pd # using DataFrame.to_html() method df = pd.read_csv("data.csv") print(df.to_html())
"data.csv"data and return it as a DataFrame.
df.to_html()will convert this data frame into HTML format.
This contains a record of three different with multiple attribute values.
View all Courses