Функция Pandas.set_option () в Python
У Pandas есть система опций, которая позволяет вам настраивать некоторые аспекты его поведения, причем параметры, связанные с отображением, - это те, которые пользователь, скорее всего, настроит. Давайте посмотрим, как установить значение указанной опции.
set_option ()
Syntax : pandas.set_option(pat, value)
Parameters :
- pat : Regexp which should match a single option.
- value : New value of option.
Returns : None
Raises : OptionError if no such option exists
Example 1 : Changing the number of rows to be displayed using display.max_rows.
# importing the moduleimport pandas as pd # creating the DataFramedata = {"Number" : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "Alphabet" : ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]}df = pd.DataFrame(data) print("Initial max_rows value : " + str(pd.options.display.max_rows)) # displaying the DataFramedisplay(df) # changing the max_rows valuepd.set_option("display.max_rows", 5) print("max_rows value after the change : " + str(pd.options.display.max_rows)) # displaying the DataFramedisplay(df) |
Output :
Example 2 : Changing the number of columns to be displayed using display.max_columns.
# importing the moduleimport pandas as pd # creating the DataFramedata = {"Number" : 1, "Name" : ["ABC"], "Subject" : ["Computer"], "Field" : ["BDA"], "Marks" : 70}df = pd.DataFrame(data) print("Initial max_columns value : " + str(pd.options.display.max_columns)) # displaying the DataFramedisplay(df) # changing the max_columns valuepd.set_option("display.max_columns", 3) print("max_columns value after the change : " + str(pd.options.display.max_columns)) # displaying the DataFramedisplay(df) |
Output :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course