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_jsonparameter isFalse, the method output will be in a human-readable format. - If the
as_jsonparameter isTrue, the method output will be in JSON format. - If the
as_jsonparameter 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 pandasprint("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
pandasmodule. - Lines 3–4: We print the output of
pandas.show_versions()method withas_jsonasFalse. - Lines 6–9: We print the output of
pandas.show_versions()method withas_jsonasTrue. - Lines 11–15: We invoke the
pandas.show_versions()method withas_jsonas a file path to the fileoutput.txt. Then print the contents ofoutput.txt.