Before the main subject
Positioning / premise
This article was prepared for the ** In-house Workshop **. Therefore, please understand that we will proceed on the following assumptions.
Purpose of this workshop
The purpose is to allow participants to ** stand at the entrance where they can self-study as needed **.
- Perform practical programming in ** hands-on format ** to gain a better understanding.
- Not all programs will be able to be organized in this workshop alone.
- When I try to make something by programming at a later date, I aim to be able to research and make it myself.
- Let's think that it's okay if you leave it lightly in your head with the feeling that something like this.
How to proceed with the workshop
The workshop basically focuses on hands-on. (Some explanations are included)
- Please use your own personal computer for business use.
- Basically, ** "copying sutras" ** is the principle.
- Copying sutras = Copying by keying yourself ≠ Copy and paste
- It is OK to copy and paste the code you wrote and then modify it.
- Enter / imprint the writing style in your head, and even if it takes time, please key in all by hand.
- IME input completion is OK.
- Please understand that trial and error due to typos is also an important factor in learning.
- The content to be introduced is ** basically something I don't understand **. Please operate everything once and then grasp the nuance, "Ah, that's how it feels."
- Don't worry deeply.
Caution
This workshop is expected to be ** 60-120 minutes **. Therefore, we do not do ** systematic learning ** because we do not have enough time for full-scale learning.
In order to be able to create the program you want from scratch in earnest, you need to study by yourself or take some kind of course.
target
This workshop is mainly aimed at the following participants.
- People who do not have programming as their main business
- People who are not good at programming or who have never created a practical program
- Beginners who do not know the basics of programming
Please note that there are many things that I do not dare to mention because I do not deal with intermediate and advanced people at all.
Preparing the programming environment
Please see here.
Today's goal
After reviewing what you learned up to the last time, you will be able to execute it in various environments.
- Iterative processing
- How to execute a function
- Four arithmetic operations
- to download
Etosetora
1. Python interpreter
Python interpreter
Run the following command:
python
Reference: 2. Using the Python interpreter — Python 3.8.2 documentation
practice
- Display Hello 10 times
- Write 10 lines of Hello to the file hello.txt
- Display the HTML of Google's top page (https://www.google.co.jp)
- Jupyter Notebook
Jupyter Notebook installation
Install the Jupyter Notebook by running the following command: (Administrator authority required)
pip install jupyter
- If you are using Anaconda, it should already be installed.
Start Jupyter Notebook
ipython notebook
Or
jupyter notebook
- Anaconda users can also start from the start menu.
Jupyter Notebook practice
-
Move
-
Code creation and modification
-
Code execution
-
How to write Markdown
-
Advantages and disadvantages of Jupyter Notebook
-
After that, execute with Jupyter Notebook.
3. Handle CSV files freely
Preparation / installation for handling CSV files
Run the following command to install the module. (Administrator authority required)
pip install pandas
Download the sample CSV file from here.
Census time series data Main time series data in CSV format|File|Find statistical data|General counter for official statistics
Import and view CSV files
import pandas
csv = pandas.read_csv('sample.csv')
print(csv)
Practice working with CSV files
- Display only the top 10 lines
- Display only 10 lines from the bottom
- Display only the prefecture name and population (total) columns.
Reference information
Answers to practice working with CSV files
Save the following contents with the file name "csv_import.ipynb" and execute it with Jupyter Notebook.
csv_import.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#CSV processing part 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Data import"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas\n",
"\n",
"csv = pandas.read_csv('sample.csv')\n",
"print(csv)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Data display"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(csv.head(10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(csv.tail(10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(csv['Name of prefectures'], csv['Population (total)'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
At the end
This time, I tried to make a workshop packed with many so that Python can be executed in various environments.
The programming / execution environment is an important factor. I hope you will use it as a basis for your future learning.
Next time, I will try various data processing using pandas introduced this time.
It's about time that we can really use it for our business!
In addition, although there are many parts where the explanation is broken, please be patient as it is for beginners.
If you would like to continue learning, please make a request.
official
Python reference site
Python related books
- [Let Python do the boring things-automated processing programming that even non-programmers can do](https://www.amazon.co.jp/%E9%80%80%E5%B1%88%E3%81%] AA% E3% 81% 93% E3% 81% A8% E3% 81% AFPython% E3% 81% AB% E3% 82% 84% E3% 82% 89% E3% 81% 9B% E3% 82% 88% E3% 81% 86-% E2% 80% 95% E3% 83% 8E% E3% 83% B3% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3 % 83% 9E% E3% 83% BC% E3% 81% AB% E3% 82% 82% E3% 81% A7% E3% 81% 8D% E3% 82% 8B% E8% 87% AA% E5% 8B % 95% E5% 8C% 96% E5% 87% A6% E7% 90% 86% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3% 83% 9F % E3% 83% B3% E3% 82% B0-Al-Sweigart / dp / 487311778X /)
- A book that inspired me to learn Python. However, the title is fishing.
- [The easiest Python introductory class](https://www.amazon.co.jp/%E3%81%84%E3%81%A1%E3%81%B0%E3%82%93%E3%82% 84% E3% 81% 95% E3% 81% 97% E3% 81% 84-Python-% E5% 85% A5% E9% 96% 80% E6% 95% 99% E5% AE% A4-% E5% A4% A7% E6% BE% A4-% E6% 96% 87% E5% AD% 9D-ebook / dp / B06Y3ZVS9Y /)
- Reputed to be easy to learn for beginners.
- [Python pretending to be readable](https://www.amazon.co.jp/%E3%82%B9%E3%83%A9%E3%82%B9%E3%83%A9%E8%AA% AD% E3% 82% 81% E3% 82% 8B-Python% E3% 81% B5% E3% 82% 8A% E3% 81% 8C% E3% 81% AA% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3% 83% 9F% E3% 83% B3% E3% 82% B0-% E6% A0% AA% E5% BC% 8F% E4% BC% 9A % E7% A4% BE% E3% 83% 93% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 82% A6% E3% 83% 89-ebook / dp / B07DR9WNKJ / ref = pd_sbs_351_2 / 358-4804238-5993600? _encoding = UTF8 & pd_rd_i = B07DR9WNKJ & pd_rd_r = 40975f9e-29b8-4fe4-b211-14a52bb1f23b & pd_rd_w = 0tyUJ & pd_rd_wg = OFv7a & pf_rd_p = ad2ea29d-ea11-483c-9db2-6b5875bb9b73 & pf_rd_r = 5SPQTNWJSKTJE8VKH4MP & psc = 1 & refRID = 5SPQTNWJSKTJE8VKH4MP)
- Same as above.