In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to automatically execute a piece of code when starting Jupyter Notebook". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to automatically execute a piece of code when starting Jupyter Notebook.
When we use Jupyter Notebook to write code, we always need to import some libraries and configure them after startup, especially for data analysis. When we open it, we must type the following code at the speed of light:
Import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn import svm, tree, linear_model, neighbors, naive_bayes, ensemble, discriminant_analysis, gaussian_process from xgboost import XGBClassifier from sklearn.preprocessing import OneHotEncoder, LabelEncoder from sklearn import feature_selection from sklearn import model_selection.
Although the amount of code is small, but every time you open notebook, you have to enter it, which is always tedious. If you use other libraries such as pyecharts, it will take a lot of time to import various packages, and it is possible that you have slipped and typed it wrong.
So is there any way to get jupter notebook/ipython to automatically load a piece of code we need when it starts? Let's share a little trick to be lazy.
You can enter the ~ / .ipython/profile_default folder under Mac (you can also find the corresponding folder in the installation directory under Windows). If you can't find this directory, you need to execute ipython profile create to generate configuration files on the command line.
As shown in the figure above, create a new folder called startup under this folder (if you have one, you don't need to create a new one), then go to the startup folder and create a new Python script start.py.
Now you can add the code that you need to type manually every time you start jupyter notebook in start.py, and then save it. After opening jupyter notebook again and creating a new notebook, you can directly use pandas, numpy and other libraries we have configured!
At this point, I believe you have a deeper understanding of "how to automatically execute a piece of code when starting Jupyter Notebook". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.