The _init_ method handles setting up a session for Notion requests, while query_database allows us to make paginated requests against a Notion database. In this case, we only need to query a database. Set up the Notion Client #Īs we’ve done in other tutorials, well make a NotionClient class to handle the Notion requests. In this tutorial, we’ll work with 3 classes - a NotionClient, handling the Notion queries, PandasConverter, handling conversion of the Notion responses into Pandas datatypes, and PandasLoader, which uses the client and converter to create a DataFrame out of the items in a database. Work with Pandas is often done interactively in a Jupyter notebook, so I’ve set up the full code example, with some bonus data analysis, as a notebook on GitHub Gists! Jupyter also comes with the Anaconda distribution, if that’s how you’ve gotten Pandas, and will also include requests, the other library we use in this tutorial. Pandas offers a load_json function to load data from a JSON format, however, the format provided by Notion doesn’t match very closely with any of the formats Pandas understands, so we’ll do some pre-processing and use the Pandas DataFrame constructor. On Windows, you may want to use the () to simplify installing the Python data science stack. ⚠️ This post assumes you already have Pandas installed and have some basic familiarity with it. Pandas can also be used as an intermediate format to output to Excel and CSV, however, if you just want to do conversion it may be better to do that directly. Pandas loads data into a Numpy backed structure called a DataFrame, which makes column and row based analysis and aggregation on mixed data types much easier. While Notion can handle some simple sums and averages, you might want to use Pandas to do more advanced analytical work on data stored in a Notion database, like visualizations or even use data from Notion for machine learning. Pandas is a popular data manipulation and analysis library in Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |