top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Table Visualization in Pandas

Writer's picture: Arpan SapkotaArpan Sapkota

This demonstrates visualization of tabular data using the Styler class.

Styler Object and HTML

Styling should be performed after the data in a DataFrame has been processed. The Styler creates an HTML and leverages CSS styling language to manipulate many parameters including colors, fonts, borders, background, etc. This allows a lot of flexibility out of the box, and even enables web developers to integrate DataFrames into their exiting user interface designs. The DataFrame.style attribute is a property that returns a Styler object.


Now lets start with the import

import pandas as pd
import numpy as np

df = pd.DataFrame(
[
  [38.0, 2.0, 18.0, 22.0, 21, np.nan],
  [19, 439, 6, 452, 226,232]
],
index=pd.Index(
['Tumour (Positive)', 'Non-Tumour (Negative)'], 
name='Actual Label:'
),
columns=pd.MultiIndex.from_product(
 [
 ['Decision Tree', 'Regression', 'Random'],
 ['Tumour', 'Non-Tumour']], 
 names=['Model:', 'Predicted:']
 )
)

Lets see the output

df.style


The above output looks very similar to the standard DataFrame HTML representation. But the HTML here has already attached some CSS classes to each cell, even if we haven’t yet created any styles. We can view these by calling the .render() method, which returns the raw HTML as string, which is useful for further processing or adding to a file - read on in More about CSS and HTML. Below we will show how we can use these to format the DataFrame to be more communicative.



0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page