You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If someone did want to convert Elements to a pandas dataframe or other data structure, including a to_dictionary function in Elements which just returns a copy of the symbol_dict would make that easier. Or add element.symbol_dict to the init.py
The text was updated successfully, but these errors were encountered:
import element.element
import pandas as pd
import json
with open(element.element.JSON_PATH) as jsonfile:
df = pd.DataFrame(json.load(jsonfile)).transpose()
print("Search by name")
print(df.set_index('name').loc['yttrium'])
print('\n')
print("Search by atomic number")
print(df.set_index('atomic number').loc[117])
print('\n')
print("Search by symbol")
print(df.set_index('symbol').loc["Rh"])
print('\n')
Yields
Search by name
symbol Y
atomic number 39
mass 88.9059
Name: yttrium, dtype: object
Search by atomic number
name ununseptium
symbol Uus
mass 291
Name: 117, dtype: object
Search by symbol
name rhodium
atomic number 45
mass 102.906
Name: Rh, dtype: object
From Parashara:
If someone did want to convert Elements to a pandas dataframe or other data structure, including a to_dictionary function in Elements which just returns a copy of the symbol_dict would make that easier. Or add element.symbol_dict to the init.py
The text was updated successfully, but these errors were encountered: