Options and settings

Overview

pandas has an options system that lets you customize some aspects of its behaviour,display-related options being those the user is most likely to adjust.

Options have a full “dotted-style”, case-insensitive name (e.g. display.max_rows).You can get/set options directly as attributes of the top-level options attribute:

  1. In [1]: import pandas as pd
  2.  
  3. In [2]: pd.options.display.max_rows
  4. Out[2]: 15
  5.  
  6. In [3]: pd.options.display.max_rows = 999
  7.  
  8. In [4]: pd.options.display.max_rows
  9. Out[4]: 999

The API is composed of 5 relevant functions, available directly from the pandasnamespace:

Note: Developers can check out pandas/core/config.py for more information.

All of the functions above accept a regexp pattern (re.search style) as an argument,and so passing in a substring will work - as long as it is unambiguous:

  1. In [5]: pd.get_option("display.max_rows")
  2. Out[5]: 999
  3.  
  4. In [6]: pd.set_option("display.max_rows", 101)
  5.  
  6. In [7]: pd.get_option("display.max_rows")
  7. Out[7]: 101
  8.  
  9. In [8]: pd.set_option("max_r", 102)
  10.  
  11. In [9]: pd.get_option("display.max_rows")
  12. Out[9]: 102

The following will not work because it matches multiple option names, e.g.display.max_colwidth, display.max_rows, display.max_columns:

  1. In [10]: try:
  2. ....: pd.get_option("column")
  3. ....: except KeyError as e:
  4. ....: print(e)
  5. ....:
  6. 'Pattern matched multiple keys'

Note: Using this form of shorthand may cause your code to break if new options with similar names are added in future versions.

You can get a list of available options and their descriptions with describe_option. When calledwith no argument describe_option will print out the descriptions for all available options.

Getting and setting options

As described above, get_option() and set_option()are available from the pandas namespace. To change an option, callset_option('option regex', new_value).

  1. In [11]: pd.get_option('mode.sim_interactive')
  2. Out[11]: False
  3.  
  4. In [12]: pd.set_option('mode.sim_interactive', True)
  5.  
  6. In [13]: pd.get_option('mode.sim_interactive')
  7. Out[13]: True

Note: The option ‘mode.sim_interactive’ is mostly used for debugging purposes.

All options also have a default value, and you can use reset_option to do just that:

  1. In [14]: pd.get_option("display.max_rows")
  2. Out[14]: 60
  3.  
  4. In [15]: pd.set_option("display.max_rows", 999)
  5.  
  6. In [16]: pd.get_option("display.max_rows")
  7. Out[16]: 999
  8.  
  9. In [17]: pd.reset_option("display.max_rows")
  10.  
  11. In [18]: pd.get_option("display.max_rows")
  12. Out[18]: 60

It’s also possible to reset multiple options at once (using a regex):

  1. In [19]: pd.reset_option("^display")

optioncontext context manager has been exposed throughthe top-level API, allowing you to execute code with given option values. Option valuesare restored automatically when you exit the _with block:

  1. In [20]: with pd.option_context("display.max_rows", 10, "display.max_columns", 5):
  2. ....: print(pd.get_option("display.max_rows"))
  3. ....: print(pd.get_option("display.max_columns"))
  4. ....:
  5. 10
  6. 5
  7.  
  8. In [21]: print(pd.get_option("display.max_rows"))
  9. 60
  10.  
  11. In [22]: print(pd.get_option("display.max_columns"))
  12. 0

Setting startup options in Python/IPython environment

Using startup scripts for the Python/IPython environment to import pandas and set options makes working with pandas more efficient. To do this, create a .py or .ipy script in the startup directory of the desired profile. An example where the startup folder is in a default ipython profile can be found at:

  1. $IPYTHONDIR/profile_default/startup

More information can be found in the ipython documentation. An example startup script for pandas is displayed below:

  1. import pandas as pd
  2. pd.set_option('display.max_rows', 999)
  3. pd.set_option('precision', 5)

Frequently Used Options

The following is a walk-through of the more frequently used display options.

display.max_rows and display.max_columns sets the maximum numberof rows and columns displayed when a frame is pretty-printed. Truncatedlines are replaced by an ellipsis.

  1. In [23]: df = pd.DataFrame(np.random.randn(7, 2))
  2.  
  3. In [24]: pd.set_option('max_rows', 7)
  4.  
  5. In [25]: df
  6. Out[25]:
  7. 0 1
  8. 0 0.469112 -0.282863
  9. 1 -1.509059 -1.135632
  10. 2 1.212112 -0.173215
  11. 3 0.119209 -1.044236
  12. 4 -0.861849 -2.104569
  13. 5 -0.494929 1.071804
  14. 6 0.721555 -0.706771
  15.  
  16. In [26]: pd.set_option('max_rows', 5)
  17.  
  18. In [27]: df
  19. Out[27]:
  20. 0 1
  21. 0 0.469112 -0.282863
  22. 1 -1.509059 -1.135632
  23. .. ... ...
  24. 5 -0.494929 1.071804
  25. 6 0.721555 -0.706771
  26.  
  27. [7 rows x 2 columns]
  28.  
  29. In [28]: pd.reset_option('max_rows')

Once the display.max_rows is exceeded, the display.min_rows optionsdetermines how many rows are shown in the truncated repr.

  1. In [29]: pd.set_option('max_rows', 8)
  2.  
  3. In [30]: pd.set_option('max_rows', 4)
  4.  
  5. # below max_rows -> all rows shown
  6. In [31]: df = pd.DataFrame(np.random.randn(7, 2))
  7.  
  8. In [32]: df
  9. Out[32]:
  10. 0 1
  11. 0 -1.039575 0.271860
  12. 1 -0.424972 0.567020
  13. .. ... ...
  14. 5 0.404705 0.577046
  15. 6 -1.715002 -1.039268
  16.  
  17. [7 rows x 2 columns]
  18.  
  19. # above max_rows -> only min_rows (4) rows shown
  20. In [33]: df = pd.DataFrame(np.random.randn(9, 2))
  21.  
  22. In [34]: df
  23. Out[34]:
  24. 0 1
  25. 0 -0.370647 -1.157892
  26. 1 -1.344312 0.844885
  27. .. ... ...
  28. 7 0.276662 -0.472035
  29. 8 -0.013960 -0.362543
  30.  
  31. [9 rows x 2 columns]
  32.  
  33. In [35]: pd.reset_option('max_rows')
  34.  
  35. In [36]: pd.reset_option('min_rows')

display.expand_frame_repr allows for the representation ofdataframes to stretch across pages, wrapped over the full column vs row-wise.

  1. In [37]: df = pd.DataFrame(np.random.randn(5, 10))
  2.  
  3. In [38]: pd.set_option('expand_frame_repr', True)
  4.  
  5. In [39]: df
  6. Out[39]:
  7. 0 1 2 3 4 5 6 7 8 9
  8. 0 -0.006154 -0.923061 0.895717 0.805244 -1.206412 2.565646 1.431256 1.340309 -1.170299 -0.226169
  9. 1 0.410835 0.813850 0.132003 -0.827317 -0.076467 -1.187678 1.130127 -1.436737 -1.413681 1.607920
  10. 2 1.024180 0.569605 0.875906 -2.211372 0.974466 -2.006747 -0.410001 -0.078638 0.545952 -1.219217
  11. 3 -1.226825 0.769804 -1.281247 -0.727707 -0.121306 -0.097883 0.695775 0.341734 0.959726 -1.110336
  12. 4 -0.619976 0.149748 -0.732339 0.687738 0.176444 0.403310 -0.154951 0.301624 -2.179861 -1.369849
  13.  
  14. In [40]: pd.set_option('expand_frame_repr', False)
  15.  
  16. In [41]: df
  17. Out[41]:
  18. 0 1 2 3 4 5 6 7 8 9
  19. 0 -0.006154 -0.923061 0.895717 0.805244 -1.206412 2.565646 1.431256 1.340309 -1.170299 -0.226169
  20. 1 0.410835 0.813850 0.132003 -0.827317 -0.076467 -1.187678 1.130127 -1.436737 -1.413681 1.607920
  21. 2 1.024180 0.569605 0.875906 -2.211372 0.974466 -2.006747 -0.410001 -0.078638 0.545952 -1.219217
  22. 3 -1.226825 0.769804 -1.281247 -0.727707 -0.121306 -0.097883 0.695775 0.341734 0.959726 -1.110336
  23. 4 -0.619976 0.149748 -0.732339 0.687738 0.176444 0.403310 -0.154951 0.301624 -2.179861 -1.369849
  24.  
  25. In [42]: pd.reset_option('expand_frame_repr')

display.large_repr lets you select whether to display dataframes that exceedmax_columns or max_rows as a truncated frame, or as a summary.

  1. In [43]: df = pd.DataFrame(np.random.randn(10, 10))
  2.  
  3. In [44]: pd.set_option('max_rows', 5)
  4.  
  5. In [45]: pd.set_option('large_repr', 'truncate')
  6.  
  7. In [46]: df
  8. Out[46]:
  9. 0 1 2 3 4 5 6 7 8 9
  10. 0 -0.954208 1.462696 -1.743161 -0.826591 -0.345352 1.314232 0.690579 0.995761 2.396780 0.014871
  11. 1 3.357427 -0.317441 -1.236269 0.896171 -0.487602 -0.082240 -2.182937 0.380396 0.084844 0.432390
  12. .. ... ... ... ... ... ... ... ... ... ...
  13. 8 -0.303421 -0.858447 0.306996 -0.028665 0.384316 1.574159 1.588931 0.476720 0.473424 -0.242861
  14. 9 -0.014805 -0.284319 0.650776 -1.461665 -1.137707 -0.891060 -0.693921 1.613616 0.464000 0.227371
  15.  
  16. [10 rows x 10 columns]
  17.  
  18. In [47]: pd.set_option('large_repr', 'info')
  19.  
  20. In [48]: df
  21. Out[48]:
  22. <class 'pandas.core.frame.DataFrame'>
  23. RangeIndex: 10 entries, 0 to 9
  24. Data columns (total 10 columns):
  25. 0 10 non-null float64
  26. 1 10 non-null float64
  27. 2 10 non-null float64
  28. 3 10 non-null float64
  29. 4 10 non-null float64
  30. 5 10 non-null float64
  31. 6 10 non-null float64
  32. 7 10 non-null float64
  33. 8 10 non-null float64
  34. 9 10 non-null float64
  35. dtypes: float64(10)
  36. memory usage: 928.0 bytes
  37.  
  38. In [49]: pd.reset_option('large_repr')
  39.  
  40. In [50]: pd.reset_option('max_rows')

display.max_colwidth sets the maximum width of columns. Cellsof this length or longer will be truncated with an ellipsis.

  1. In [51]: df = pd.DataFrame(np.array([['foo', 'bar', 'bim', 'uncomfortably long string'],
  2. ....: ['horse', 'cow', 'banana', 'apple']]))
  3. ....:
  4.  
  5. In [52]: pd.set_option('max_colwidth', 40)
  6.  
  7. In [53]: df
  8. Out[53]:
  9. 0 1 2 3
  10. 0 foo bar bim uncomfortably long string
  11. 1 horse cow banana apple
  12.  
  13. In [54]: pd.set_option('max_colwidth', 6)
  14.  
  15. In [55]: df
  16. Out[55]:
  17. 0 1 2 3
  18. 0 foo bar bim un...
  19. 1 horse cow ba... apple
  20.  
  21. In [56]: pd.reset_option('max_colwidth')

display.max_info_columns sets a threshold for when by-column infowill be given.

  1. In [57]: df = pd.DataFrame(np.random.randn(10, 10))
  2.  
  3. In [58]: pd.set_option('max_info_columns', 11)
  4.  
  5. In [59]: df.info()
  6. <class 'pandas.core.frame.DataFrame'>
  7. RangeIndex: 10 entries, 0 to 9
  8. Data columns (total 10 columns):
  9. 0 10 non-null float64
  10. 1 10 non-null float64
  11. 2 10 non-null float64
  12. 3 10 non-null float64
  13. 4 10 non-null float64
  14. 5 10 non-null float64
  15. 6 10 non-null float64
  16. 7 10 non-null float64
  17. 8 10 non-null float64
  18. 9 10 non-null float64
  19. dtypes: float64(10)
  20. memory usage: 928.0 bytes
  21.  
  22. In [60]: pd.set_option('max_info_columns', 5)
  23.  
  24. In [61]: df.info()
  25. <class 'pandas.core.frame.DataFrame'>
  26. RangeIndex: 10 entries, 0 to 9
  27. Columns: 10 entries, 0 to 9
  28. dtypes: float64(10)
  29. memory usage: 928.0 bytes
  30.  
  31. In [62]: pd.reset_option('max_info_columns')

display.max_info_rows: df.info() will usually show null-counts for each column.For large frames this can be quite slow. max_info_rows and max_info_colslimit this null check only to frames with smaller dimensions then specified. Note that youcan specify the option df.info(null_counts=True) to override on showing a particular frame.

  1. In [63]: df = pd.DataFrame(np.random.choice([0, 1, np.nan], size=(10, 10)))
  2.  
  3. In [64]: df
  4. Out[64]:
  5. 0 1 2 3 4 5 6 7 8 9
  6. 0 0.0 NaN 1.0 NaN NaN 0.0 NaN 0.0 NaN 1.0
  7. 1 1.0 NaN 1.0 1.0 1.0 1.0 NaN 0.0 0.0 NaN
  8. 2 0.0 NaN 1.0 0.0 0.0 NaN NaN NaN NaN 0.0
  9. 3 NaN NaN NaN 0.0 1.0 1.0 NaN 1.0 NaN 1.0
  10. 4 0.0 NaN NaN NaN 0.0 NaN NaN NaN 1.0 0.0
  11. 5 0.0 1.0 1.0 1.0 1.0 0.0 NaN NaN 1.0 0.0
  12. 6 1.0 1.0 1.0 NaN 1.0 NaN 1.0 0.0 NaN NaN
  13. 7 0.0 0.0 1.0 0.0 1.0 0.0 1.0 1.0 0.0 NaN
  14. 8 NaN NaN NaN 0.0 NaN NaN NaN NaN 1.0 NaN
  15. 9 0.0 NaN 0.0 NaN NaN 0.0 NaN 1.0 1.0 0.0
  16.  
  17. In [65]: pd.set_option('max_info_rows', 11)
  18.  
  19. In [66]: df.info()
  20. <class 'pandas.core.frame.DataFrame'>
  21. RangeIndex: 10 entries, 0 to 9
  22. Data columns (total 10 columns):
  23. 0 8 non-null float64
  24. 1 3 non-null float64
  25. 2 7 non-null float64
  26. 3 6 non-null float64
  27. 4 7 non-null float64
  28. 5 6 non-null float64
  29. 6 2 non-null float64
  30. 7 6 non-null float64
  31. 8 6 non-null float64
  32. 9 6 non-null float64
  33. dtypes: float64(10)
  34. memory usage: 928.0 bytes
  35.  
  36. In [67]: pd.set_option('max_info_rows', 5)
  37.  
  38. In [68]: df.info()
  39. <class 'pandas.core.frame.DataFrame'>
  40. RangeIndex: 10 entries, 0 to 9
  41. Data columns (total 10 columns):
  42. 0 float64
  43. 1 float64
  44. 2 float64
  45. 3 float64
  46. 4 float64
  47. 5 float64
  48. 6 float64
  49. 7 float64
  50. 8 float64
  51. 9 float64
  52. dtypes: float64(10)
  53. memory usage: 928.0 bytes
  54.  
  55. In [69]: pd.reset_option('max_info_rows')

display.precision sets the output display precision in terms of decimal places.This is only a suggestion.

  1. In [70]: df = pd.DataFrame(np.random.randn(5, 5))
  2.  
  3. In [71]: pd.set_option('precision', 7)
  4.  
  5. In [72]: df
  6. Out[72]:
  7. 0 1 2 3 4
  8. 0 -1.1506406 -0.7983341 -0.5576966 0.3813531 1.3371217
  9. 1 -1.5310949 1.3314582 -0.5713290 -0.0266708 -1.0856630
  10. 2 -1.1147378 -0.0582158 -0.4867681 1.6851483 0.1125723
  11. 3 -1.4953086 0.8984347 -0.1482168 -1.5960698 0.1596530
  12. 4 0.2621358 0.0362196 0.1847350 -0.2550694 -0.2710197
  13.  
  14. In [73]: pd.set_option('precision', 4)
  15.  
  16. In [74]: df
  17. Out[74]:
  18. 0 1 2 3 4
  19. 0 -1.1506 -0.7983 -0.5577 0.3814 1.3371
  20. 1 -1.5311 1.3315 -0.5713 -0.0267 -1.0857
  21. 2 -1.1147 -0.0582 -0.4868 1.6851 0.1126
  22. 3 -1.4953 0.8984 -0.1482 -1.5961 0.1597
  23. 4 0.2621 0.0362 0.1847 -0.2551 -0.2710

display.chop_threshold sets at what level pandas rounds to zero whenit displays a Series of DataFrame. This setting does not change theprecision at which the number is stored.

  1. In [75]: df = pd.DataFrame(np.random.randn(6, 6))
  2.  
  3. In [76]: pd.set_option('chop_threshold', 0)
  4.  
  5. In [77]: df
  6. Out[77]:
  7. 0 1 2 3 4 5
  8. 0 1.2884 0.2946 -1.1658 0.8470 -0.6856 0.6091
  9. 1 -0.3040 0.6256 -0.0593 0.2497 1.1039 -1.0875
  10. 2 1.9980 -0.2445 0.1362 0.8863 -1.3507 -0.8863
  11. 3 -1.0133 1.9209 -0.3882 -2.3144 0.6655 0.4026
  12. 4 0.3996 -1.7660 0.8504 0.3881 0.9923 0.7441
  13. 5 -0.7398 -1.0549 -0.1796 0.6396 1.5850 1.9067
  14.  
  15. In [78]: pd.set_option('chop_threshold', .5)
  16.  
  17. In [79]: df
  18. Out[79]:
  19. 0 1 2 3 4 5
  20. 0 1.2884 0.0000 -1.1658 0.8470 -0.6856 0.6091
  21. 1 0.0000 0.6256 0.0000 0.0000 1.1039 -1.0875
  22. 2 1.9980 0.0000 0.0000 0.8863 -1.3507 -0.8863
  23. 3 -1.0133 1.9209 0.0000 -2.3144 0.6655 0.0000
  24. 4 0.0000 -1.7660 0.8504 0.0000 0.9923 0.7441
  25. 5 -0.7398 -1.0549 0.0000 0.6396 1.5850 1.9067
  26.  
  27. In [80]: pd.reset_option('chop_threshold')

display.colheader_justify controls the justification of the headers.The options are ‘right’, and ‘left’.

  1. In [81]: df = pd.DataFrame(np.array([np.random.randn(6),
  2. ....: np.random.randint(1, 9, 6) * .1,
  3. ....: np.zeros(6)]).T,
  4. ....: columns=['A', 'B', 'C'], dtype='float')
  5. ....:
  6.  
  7. In [82]: pd.set_option('colheader_justify', 'right')
  8.  
  9. In [83]: df
  10. Out[83]:
  11. A B C
  12. 0 0.1040 0.1 0.0
  13. 1 0.1741 0.5 0.0
  14. 2 -0.4395 0.4 0.0
  15. 3 -0.7413 0.8 0.0
  16. 4 -0.0797 0.4 0.0
  17. 5 -0.9229 0.3 0.0
  18.  
  19. In [84]: pd.set_option('colheader_justify', 'left')
  20.  
  21. In [85]: df
  22. Out[85]:
  23. A B C
  24. 0 0.1040 0.1 0.0
  25. 1 0.1741 0.5 0.0
  26. 2 -0.4395 0.4 0.0
  27. 3 -0.7413 0.8 0.0
  28. 4 -0.0797 0.4 0.0
  29. 5 -0.9229 0.3 0.0
  30.  
  31. In [86]: pd.reset_option('colheader_justify')

Available options

OptionDefaultFunction
display.chopthresholdNoneIf set to a float value, all floatvalues smaller then the giventhreshold will be displayed asexactly 0 by repr and friends.
display.colheader_justifyrightControls the justification ofcolumn headers. used by DataFrameFormatter.
display.column_space12No description available.
display.date_dayfirstFalseWhen True, prints and parses dateswith the day first, eg 20/01/2005
display.date_yearfirstFalseWhen True, prints and parses dateswith the year first, eg 2005/01/20
display.encodingUTF-8Defaults to the detected encodingof the console. Specifies the encodingto be used for strings returned byto_string, these are generally stringsmeant to be displayed on the console.
display.expand_frame_reprTrueWhether to print out the full DataFramerepr for wide DataFrames acrossmultiple lines, _max_columns isstill respected, but the output willwrap-around across multiple “pages”if its width exceeds display.width.
display.floatformatNoneThe callable should accept a floatingpoint number and return a string withthe desired format of the number.This is used in some places likeSeriesFormatter.See core.format.EngFormatter for an example.
display.largereprtruncateFor DataFrames exceeding maxrows/max_cols,the repr (and HTML repr) can showa truncated table (the default),or switch to the view from df.info()(the behaviour in earlier versions of pandas).allowable settings, [‘truncate’, ‘info’]
display.latex.reprFalseWhether to produce a latex DataFramerepresentation for jupyter frontendsthat support it.
display.latex.escapeTrueEscapes special characters in DataFrames, whenusing the to_latex method.
display.latex.longtableFalseSpecifies if the to_latex method of a DataFrameuses the longtable format.
display.latex.multicolumnTrueCombines columns when using a MultiIndex
display.latex.multicolumn_format‘l’Alignment of multicolumn labels
display.latex.multirowFalseCombines rows when using a MultiIndex.Centered instead of top-aligned,separated by clines.
display.max_columns0 or 20max_rows and max_columns are usedin __repr() methods to decide ifto_string() or info() is used torender an object to a string. Incase Python/IPython is running ina terminal this is set to 0 by default andpandas will correctly auto-detectthe width of the terminal and switch toa smaller format in case all columnswould not fit vertically. The IPythonnotebook, IPython qtconsole, or IDLEdo not run in a terminal and henceit is not possible to do correctauto-detection, in which case the defaultis set to 20. ‘None’ value means unlimited.
display.max_colwidth50The maximum width in characters ofa column in the repr of a pandasdata structure. When the column overflows,a “…” placeholder is embedded inthe output.
display.max_info_columns100max_info_columns is used in DataFrame.infomethod to decide if per column informationwill be printed.
display.max_info_rows1690785df.info() will usually show null-countsfor each column. For large framesthis can be quite slow. max_info_rowsand max_info_cols limit this nullcheck only to frames with smallerdimensions then specified.
display.max_rows60This sets the maximum number of rowspandas should output when printingout various output. For example,this value determines whether therepr() for a dataframe prints outfully or just a truncated or summary repr.‘None’ value means unlimited.
display.min_rows10The numbers of rows to show in a truncatedrepr (when _max_rows is exceeded). Ignoredwhen max_rows is set to None or 0. When setto None, follows the value of max_rows.
display.maxseq_items100when pretty-printing a long sequence,no more then _max_seq_items willbe printed. If items are omitted,they will be denoted by the additionof “…” to the resulting string.If set to None, the number of itemsto be printed is unlimited.
display.memory_usageTrueThis specifies if the memory usage ofa DataFrame should be displayed when thedf.info() method is invoked.
display.multi_sparseTrue“Sparsify” MultiIndex display (don’tdisplay repeated elements in outerlevels within groups)
display.notebook_repr_htmlTrueWhen True, IPython notebook willuse html representation forpandas objects (if it is available).
display.pprint_nest_depth3Controls the number of nested levelsto process when pretty-printing
display.precision6Floating point output precision interms of number of places after thedecimal, for regular formatting as wellas scientific notation. Similar tonumpy’s precision print option
display.show_dimensionstruncateWhether to print out dimensionsat the end of DataFrame repr.If ‘truncate’ is specified, onlyprint out the dimensions if theframe is truncated (e.g. not displayall rows and/or columns)
display.width80Width of the display in characters.In case python/IPython is running ina terminal this can be set to Noneand pandas will correctly auto-detectthe width. Note that the IPython notebook,IPython qtconsole, or IDLE do not run in aterminal and hence it is not possibleto correctly detect the width.
display.html.table_schemaFalseWhether to publish a Table Schemarepresentation for frontends thatsupport it.
display.html.border1A border=value attribute isinserted in the <table> tagfor the DataFrame HTML repr.
display.html.use_mathjaxTrueWhen True, Jupyter notebook will processtable contents using MathJax, renderingmathematical expressions enclosed by thedollar symbol.
io.excel.xls.writerxlwtThe default Excel writer engine for‘xls’ files.
io.excel.xlsm.writeropenpyxlThe default Excel writer engine for‘xlsm’ files. Available options:‘openpyxl’ (the default).
io.excel.xlsx.writeropenpyxlThe default Excel writer engine for‘xlsx’ files.
io.hdf.default_formatNonedefault format writing format, ifNone, then put will default to‘fixed’ and append will default to‘table’
io.hdf.dropna_tableTruedrop ALL nan rows when appendingto a table
io.parquet.engineNoneThe engine to use as a default forparquet reading and writing. If Nonethen try ‘pyarrow’ and ‘fastparquet’
mode.chained_assignmentwarnControls SettingWithCopyWarning:‘raise’, ‘warn’, or None. Raise anexception, warn, or no action iftrying to use chained assignment.
mode.sim_interactiveFalseWhether to simulate interactive modefor purposes of testing.
mode.use_inf_as_naFalseTrue means treat None, NaN, -INF,INF as NA (old way), False meansNone and NaN are null, but INF, -INFare not NA (new way).
compute.use_bottleneckTrueUse the bottleneck library to acceleratecomputation if it is installed.
compute.use_numexprTrueUse the numexpr library to acceleratecomputation if it is installed.
plotting.backendmatplotlibChange the plotting backend to a differentbackend than the current matplotlib one.Backends can be implemented as third-partylibraries implementing the pandas plottingAPI. They can use other plotting librarieslike Bokeh, Altair, etc.
plotting.matplotlib.register_convertersTrueRegister custom converters withmatplotlib. Set to False to de-register.

Number formatting

pandas also allows you to set how numbers are displayed in the console.This option is not set through the set_options API.

Use the set_eng_float_format functionto alter the floating-point formatting of pandas objects to produce a particularformat.

For instance:

  1. In [87]: import numpy as np
  2.  
  3. In [88]: pd.set_eng_float_format(accuracy=3, use_eng_prefix=True)
  4.  
  5. In [89]: s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
  6.  
  7. In [90]: s / 1.e3
  8. Out[90]:
  9. a 303.638u
  10. b -721.084u
  11. c -622.696u
  12. d 648.250u
  13. e -1.945m
  14. dtype: float64
  15.  
  16. In [91]: s / 1.e6
  17. Out[91]:
  18. a 303.638n
  19. b -721.084n
  20. c -622.696n
  21. d 648.250n
  22. e -1.945u
  23. dtype: float64

To round floats on a case-by-case basis, you can also use round() and round().

Unicode formatting

Warning

Enabling this option will affect the performance for printing of DataFrame and Series (about 2 times slower).Use only when it is actually required.

Some East Asian countries use Unicode characters whose width corresponds to two Latin characters.If a DataFrame or Series contains these characters, the default output mode may not align them properly.

Note

Screen captures are attached for each output to show the actual results.

  1. In [92]: df = pd.DataFrame({'国籍': ['UK', '日本'], '名前': ['Alice', 'しのぶ']})
  2.  
  3. In [93]: df
  4. Out[93]:
  5. 国籍 名前
  6. 0 UK Alice
  7. 1 日本 しのぶ

../_images/option_unicode01.pngEnabling display.unicode.east_asian_width allows pandas to check each character’s “East Asian Width” property.These characters can be aligned properly by setting this option to True. However, this will result in longer rendertimes than the standard len function.

  1. In [94]: pd.set_option('display.unicode.east_asian_width', True)
  2.  
  3. In [95]: df
  4. Out[95]:
  5. 国籍 名前
  6. 0 UK Alice
  7. 1 日本 しのぶ

../_images/option_unicode02.pngIn addition, Unicode characters whose width is “Ambiguous” can either be 1 or 2 characters wide depending on theterminal setting or encoding. The option display.unicode.ambiguous_as_wide can be used to handle the ambiguity.

By default, an “Ambiguous” character’s width, such as “¡” (inverted exclamation) in the example below, is taken to be 1.

  1. In [96]: df = pd.DataFrame({'a': ['xxx', '¡¡'], 'b': ['yyy', '¡¡']})
  2.  
  3. In [97]: df
  4. Out[97]:
  5. a b
  6. 0 xxx yyy
  7. 1 ¡¡ ¡¡

../_images/option_unicode03.pngEnabling display.unicode.ambiguous_as_wide makes pandas interpret these characters’ widths to be 2.(Note that this option will only be effective when display.unicode.east_asian_width is enabled.)

However, setting this option incorrectly for your terminal will cause these characters to be aligned incorrectly:

  1. In [98]: pd.set_option('display.unicode.ambiguous_as_wide', True)
  2.  
  3. In [99]: df
  4. Out[99]:
  5. a b
  6. 0 xxx yyy
  7. 1 ¡¡ ¡¡

../_images/option_unicode04.png

Table schema display

New in version 0.20.0.

DataFrame and Series will publish a Table Schema representationby default. False by default, this can be enabled globally with thedisplay.html.table_schema option:

  1. In [100]: pd.set_option('display.html.table_schema', True)

Only 'display.max_rows' are serialized and published.