What is the show_versions method in pandas?

Overview

The show_versions method contains information on the hosting operating system, pandas version, and versions of other related modules that have been installed.

Note: Refer to What is pandas in Python to learn more about pandas.

Syntax

show_versions(as_json: Union[str, bool] = False) -> None

Parameter

The method optionally takes a parameter called as_json. The default value of the parameter is False. The possible values the parameter can take are as follows:

  • If the as_json parameter is False, the method output will be in a human-readable format.
  • If the as_json parameter is True, the method output will be in JSON format.
  • If the as_json parameter is a string, then the method considers the passed value as the path to the file where the output will be written in JSON format.

Code

import pandas
print("pandas.show_versions(as_json=False) = ")
pandas.show_versions(as_json=False)
print("\n")
print("--" * 8)
print("pandas.show_versions(as_json=True) = ")
pandas.show_versions(as_json=True)
print("\n")
print("--" * 8)
pandas.show_versions(as_json="output.txt")
print("Contents of output.txt")
print(open("output.txt").read())

Explanation

  • Line 1: We import the pandas module.
  • Lines 3–4: We print the output of pandas.show_versions() method with as_json as False.
  • Lines 6–9: We print the output of pandas.show_versions() method with as_json as True.
  • Lines 11–15: We invoke the pandas.show_versions() method with as_json as a file path to the file output.txt. Then print the contents of output.txt.

Free Resources