#!/usr/bin/env python # coding: utf-8 # # Bulk data access # # This tutorial explains how to retrieve full tables from the database into [pandas DataFrames](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html). # # ## The following tables are available from ``mendeleev`` # # * elements # * ionicradii # * ionizationenergies # * oxidationstates # * groups # * series # * isotopes # # All data is stored in a sqlite database that is shipped together with the package. You can interact directly with the database if you need more flexibility but for convenience ``mendeleev`` provides a few functions in the `fetch` module to # retrieve data. # # To fetch whole tables you can use `fetch_table`. The function can be imported from `mendeleev.fetch` # In[1]: from mendeleev.fetch import fetch_table # To retrieve a table call the ``fetch_table`` with the table name as argument. Here we'll get probably the most important table ``elements`` with basis data on each element # In[3]: ptable = fetch_table("elements") # Now we can use [pandas'](http://pandas.pydata.org) capabilities to work with the data. # In[4]: ptable.info() # For clarity let's take only a subset of columns # In[5]: cols = [ "atomic_number", "symbol", "atomic_radius", "en_pauling", "block", "vdw_radius_mm3", ] # In[6]: ptable[cols].head() # It is quite easy now to get descriptive statistics on the data. # In[7]: ptable[cols].describe() # ## Isotopes table # # Let try and retrieve another table, namely ``isotopes`` # In[8]: isotopes = fetch_table("isotopes", index_col="id") # In[9]: isotopes.info() # ### Merge the elements table with the isotopes # # We can now perform SQL-like merge operation on two ``DataFrame``s and produce an [outer](http://pandas.pydata.org/pandas-docs/stable/merging.html#database-style-dataframe-joining-merging) join # In[10]: import pandas as pd # In[11]: merged = pd.merge(ptable[cols], isotopes, how="outer", on="atomic_number") # now we have the following columns in the ``merged`` ``DataFrame`` # In[12]: merged.info() # In[13]: merged.head() # To display all the isotopes of Silicon # In[14]: merged[merged["symbol"] == "Si"] # ## Ionic radii # # The function to fetch ionic radii is called `fetch_ionic_radii` and can either fetch ionic or crystal radii depending on the `radius` argument. # In[2]: from mendeleev.fetch import fetch_ionic_radii # In[3]: irs = fetch_ionic_radii(radius="ionic_radius") irs.head(10) # ## Ionization energies # # To fetch ionization energies use `fetch_ionization_energies` that takes a `degree` (default is `degree=1`) argument that can either be a single integer or a list if integers to fetch multiple ionization energies. # In[17]: from mendeleev.fetch import fetch_ionization_energies # In[25]: ies = fetch_ionization_energies(degree=2) ies.head(10) # In[24]: ies_multiple = fetch_ionization_energies(degree=[1, 3, 5]) ies_multiple.head(10) # ## Electronegativities # # To fetch all data from electronegatuivity scales use `fetch_electronegativities`. This can take a few seconds since most of the values need to be computed. # In[26]: from mendeleev.fetch import fetch_electronegativities # In[27]: ens = fetch_electronegativities() ens.head(10)