Dear Members,
I am using new API to access data.
Code to access data is:
Search result with new API [ mpr.summary.search() ] is :
How to get search result in the following format?(this was from leagcy API [mpr.query() ] )
Dear Members,
I am using new API to access data.
Code to access data is:
Search result with new API [ mpr.summary.search() ] is :
How to get search result in the following format?(this was from leagcy API [mpr.query() ] )
Dear @Jameer
The results from the new API are MPDataDoc
objects rather than dict
objects that the old API would return. MPDataDoc
objects can be converted to dict
objects using the MPDataDoc.dict()
method.
So for your example, we can do the following:
from mp_api.client import MPRester
from emmet.core.summary import HasProps
import pandas as pd
with MPRester(API_KEY) as mpr:
docs = mpr.summary.search(has_props=[HasProps.dielectric], fields =["material_id","band_gap", "structure"])
# Convert docs to dict
docs_dict = [doc.dict(exclude={"fields_not_requested"}) for doc in docs]
# Put in a dataframe
df = pd.DataFrame(docs_dict)
df.head()
Let me know if this solves your problem.
Dear Anthony
It is working. Thanks a lot
Thanks @AntObi!