文档详情

Python数据分析基础与应用电子活页4-10设置Pandas数据显示格式.docx

发布:2025-05-26约小于1千字共1页下载文档
文本预览下载声明

Python数据分析基础与应用

模块

PAGE2

PAGE21

电子活页4-10设置pandas数据显示格式

【技能训练4-14】在JupyterNotebook开发环境中设置pandas数据显示格式

【训练要求】

在JupyterNotebook开发环境中创建j4-14.ipynb,然后编写代码设置pandas数据显示格式。

【实施过程】

代码如下:

importpandasaspd

print(pd.get_option(display.max_rows))

print(pd.get_option(display.max_columns))

pd.set_option(display.max_rows,70)

print(pd.get_option(display.max_rows))

pd.set_option(display.max_columns,40)

print(pd.get_option(display.max_columns))

#恢复为默认值

pd.reset_option(display.max_rows)

print(pd.get_option(display.max_rows))

pd.reset_option(display.max_columns)

print(pd.get_option(display.max_columns))

#以下第1个print语句输出option_context()设置的临时值

#当退出with语句块时,第2个print语句输出解释器默认值

withpd.option_context(display.max_rows,10):

print(pd.get_option(display.max_rows))

print(pd.get_option(display.max_rows))

输出结果:

60

20

70

40

60

20

10

60

显示全部
相似文档