IPython for Py: Introduction to the display function in the IPython library, how to use it, and a detailed guide to application cases

IPython for Py: Introduction to the display function in the IPython library, how to use it, and a detailed guide to application cases

Table of contents

Introduction to the display function

How to use the display function

1. Basic usage

Application case of display function

1. Display a string, display a Pandas data frame, display a picture, display a piece of HTML code


Introduction to the display function

The display function is a built-in function of IPython that is used to display graphical representations or other formatted output of Python objects , such as images, audio, video, HTML, etc.,         in the Jupyter Notebook environment .
        The display function can accept one or more arguments, each of which is a Python object. It will automatically select the appropriate display method according to the type of object and display it in Jupyter Notebook . If you need to display multiple objects in the same cell, you can list these objects one by one in the display function.

How to use the display function

1. Basic usage

from IPython.display import display
display(spark_df_preds)

Application case of display function

1. Display a string , display a Pandas data frame , display a picture , display a piece of HTML code

from IPython.display import display
import pandas as pd

# 显示一个字符串
display('Hello, world!')

# 显示一个 Pandas 数据框
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
display(df)

# 显示一张图片
from PIL import Image
img = Image.open('image.jpg')
display(img)

# 显示一段 HTML 代码
display('<h1>This is a heading</h1>')

Guess you like

Origin blog.csdn.net/qq_41185868/article/details/130118980