在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:gregtam/jupyter-notebook-initializer开源软件地址:https://github.com/gregtam/jupyter-notebook-initializer开源编程语言:Jupyter Notebook 98.8%开源软件介绍:jupyter-notebook-initializerThe goal of this repository is to serve as a template for any new projects to avoid the hassle of configuring all the options each time a new project is started. The file notebook_initializer.ipynb serves as a starting point for any Jupyter notebook by importing useful libraries and setting up default settings (e.g., plotting settings, SQL magic functions). FilesNotebooks
Python Files
Submodules
ExamplesWe now show some examples of how to use these magic functions. Executing SQL QueriesWe can execute SQL commands simply by typing regular SQL code and putting an
Reading SQL Query OutputsWe can also read SQL query outputs and store them into a pandas DataFrame by putting
If the outputted DataFrame has too many rows, we can also look at the head by typing
Additionally, if we wanted to store this table to a different DataFrame, we can include this at the end of the top line of the cell.
One final possibility is to use string formatting. Suppose we have the name of the table as a variable in Python.
We can then select use this variable in our SQL query string.
Printing SQL QueriesWhile writing our SQL queries with string formatting, we may want to view the query beforehand as it there may be errors. We want to do this via the
Autofill Table NamesWhen tables are created, the Threading/Background ProcessesThreading allows us to run two or more cells concurrently. This is useful if we have a long query running, but want to test other stuff inside of the same notebook and use the same variables. We make use of the A simple background thread being called:
A background thread with a comment:
We can also separate a cell of code into separate sections, which will individually run in parallel in the background. We do this using lines that begin with two or more '#' characters. Any following characters in the line go towards the thread's comment.
The notebook will automatically create a
This returns a DataFrame showing all completed and uncompleted threads. It also displays their start and end times, the total time for the code to run, and the comment. If there was an error in the code, then it will display that instead of the end time and completion time. We can also filter and show only finished or unfinished threads by running:
Again, these return DataFrames. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论