Debian Codegraph @

docs/guide/pandas.md

raw
1 (pandas)=
2
3 # *pandas* integration
4
5 ## Installing *pandas*
6
7 *pandas* must be installed to use its functionality from within PubChemPy. It is an optional dependency, so it is not installed automatically with PubChemPy. The easiest way is to use pip:
8
9 ```bash
10 pip install pandas
11 ```
12
13 See the [pandas documentation](https://pandas.pydata.org/pandas-docs/stable/) for more information.
14
15 ## Usage
16
17 It is possible for {func}`~pubchempy.get_compounds`, {func}`~pubchempy.get_substances` and {func}`~pubchempy.get_properties` to return a pandas DataFrame:
18
19 ```python
20 df1 = pcp.get_compounds("C20H41Br", "formula", as_dataframe=True)
21 df2 = pcp.get_substances([1, 2, 3, 4], as_dataframe=True)
22 df3 = pcp.get_properties(["smiles", "xlogp", "rotatable_bond_count"], "C20H41Br", "formula", as_dataframe=True)
23 ```
24
25 An existing list of {class}`~pubchempy.Compound` objects can be converted into a dataframe, optionally specifying the desired columns:
26
27 ```python
28 cs = pcp.get_compounds("C20H41Br", "formula")
29 df4 = pcp.compounds_to_frame(cs, properties=["smiles", "xlogp", "rotatable_bond_count"])
30 ```