Accessing data¶
Tip
If you’re looking for raw data behind mendeleev have a look at mendeleev-data repo.
You can find all data assets in multiple formats:
csv,
html,
json,
sql,
markdown.
All releases a tagged with the same version numbers as mendeleev.
Individual Elements¶
The easiest way to access individual elements is simply by importing them from the mendeleev directly using their symbols:
>>> from mendeleev import H, C, O, Og
>>> [x.name for x in [H, C, O, Og]]
['Hydrogen', 'Carbon', 'Oxygen', 'Oganesson']
An alternative method of access is through the element() function that
returns either a single Element instance or a tuple of those instances depending on the input. It provides a more flexible interface
since it accepts element names, atomic numbers and symbols as well as their combinations.
Fetching data in bulk¶
If you want a whole set of data you can retrieve one of the tables from the
database as pandas
DataFrame through the fetch_table(). The following
tables are available:
- fetch_table(table: str, **kwargs) DataFrame[source]¶
Return a table from the database as
pandas.DataFrame- Parameters:¶
- Returns:¶
Pandas DataFrame with the contents of the table
- Return type:¶
df (pandas.DataFrame)
Example
>>> from mendeleev.fetch import fetch_table >>> df = fetch_table('elements') >>> type(df) pandas.core.frame.DataFrame
-
fetch_ionization_energies(degree: list[int] | int =
1) DataFrame[source]¶ Fetch a
pandas.DataFramewith ionization energies for all elements indexed by atomic number.- Parameters:¶
- Returns:¶
ionization energies, indexed by atomic number
- Return type:¶
df (pandas.DataFrame)
-
fetch_ionic_radii(radius: str =
'ionic_radius') DataFrame[source]¶ Fetch a pandas DataFrame with ionic radii for all the elements.
Computed properties¶
Some properties need to be computed rather than directly retrieved from the database. Electronegativities
-
fetch_electronegativities(scales: list[str] | None =
None) DataFrame[source]¶ Fetch electronegativity scales for all elements as
pandas.DataFrame- Parameters:¶
- Returns:¶
Pandas DataFrame with the contents of the table
- Return type:¶
df (pandas.DataFrame)
Database session and engine¶
For those how want to interact with the database through a layer of SQLAlchemy there are methods for getting the session or the engine:
-
get_session(dbpath: str =
None, read_only: bool =True) Session[source]¶ Return the database session connection.
Export data¶
The data can be exported to a number of formats using the CLI by invoking inv export command. The following formats are supported:
csv
json
html
markdown
The command will export all the tables from the database to a set of files in the specified format.
In order to use this functionality you’ll need to clone the mendeleev repository and install the package in the development mode. Here’s how you can do it:
git clone https://github.com/lmmentel/mendeleev.git
cd mendeleev
poetry install
poetry run inv export
After the command is executed you’ll find the exported files in the data directory. The contents should look like this:
data
├── csv
│ ├── elements.csv
│ ├── groups.csv
│ ├── ionicradii.csv
│ ├── ionizationenergies.csv
│ ├── isotopedecaymodes.csv
│ ├── isotopes.csv
│ ├── oxidationstates.csv
│ ├── phasetransitions.csv
│ ├── screeningconstants.csv
│ └── series.csv
├── html
│ ├── elements.html
│ ├── groups.html
│ ├── ionicradii.html
│ ├── ionizationenergies.html
│ ├── isotopedecaymodes.html
│ ├── isotopes.html
│ ├── oxidationstates.html
│ ├── phasetransitions.html
│ ├── screeningconstants.html
│ └── series.html
├── json
│ ├── elements.json
│ ├── groups.json
│ ├── ionicradii.json
│ ├── ionizationenergies.json
│ ├── isotopedecaymodes.json
│ ├── isotopes.json
│ ├── oxidationstates.json
│ ├── phasetransitions.json
│ ├── screeningconstants.json
│ └── series.json
└── markdown
├── elements.markdown
├── groups.markdown
├── ionicradii.markdown
├── ionizationenergies.markdown
├── isotopedecaymodes.markdown
├── isotopes.markdown
├── oxidationstates.markdown
├── phasetransitions.markdown
├── screeningconstants.markdown
└── series.markdown