You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<SubHeading>Short introduction to Python</SubHeading>
8
+
<SubHeading>Short introduction to Python</SubHeading>
9
9
10
-
[Python](https://www.python.org/) is a general-purpose coding language—which means that, unlike HTML, CSS, and JavaScript, it can be used for other types of programming and software development besides web development. Python is interpreted, easy to learn surrounded by a huge ecosystem, actively supported and used in many industries and domains - Resources:
10
+
[Python](https://www.python.org/) is a general-purpose coding language—which means that, unlike HTML, CSS, and JavaScript,
11
+
it can be used for other types of programming and software development besides web development.
11
12
12
-
-[Python](https://www.python.org/) - the official website
13
-
-[Python For Beginners](https://www.python.org/about/gettingstarted/) - a starting guide  
14
-
-[Python Cheatsheet](https://www.pythoncheatsheet.org/) - this site should make you curious
15
-
-[Flask](https://flask.palletsprojects.com/en/1.1.x/) - popular Python web framework 
13
+
Python is interpreted, easy to learn surrounded by a huge ecosystem, actively supported and used in many industries and domains.
16
14
17
-
**Can be used for things like**: (starting from the simple ones)
15
+
> **Can be used for things like**: (starting from the simple ones)
18
16
19
17
- Basic programming: using strings, adding numbers, open files
20
18
- Writing system scripts (creating instructions that tell a computer system to “do” something)
21
19
- Back end (or server-side) web and mobile app development
22
20
- Desktop apps and software development
23
21
- Processing big data and performing mathematical computations
The **Python** can be downloaded from the [official website](https://www.python.org/). Choose the installer for your operating system, download, and click a few times. By typing python --version in a terminal window, you should see something like this:
25
+
The **Python** can be downloaded from the [official website](https://www.python.org/).
26
+
Choose the installer for your operating system, download, and click a few times. By typing python --version in a terminal window, you should see something like this:
28
27
29
28
```bash
30
29
$ python --version
31
-
Python 3.7.2
30
+
Python 3.9.12
32
31
```
33
32
34
-
###
35
-
36
-
### Coding in Python
33
+
## ✅ Coding in Python
37
34
38
35
To start using Python we need to open a terminal, type `python` and we should be see the python console waiting for input.
39
36
@@ -79,11 +76,10 @@ TypeError: can only concatenate str (not "int") to str
79
76
'text 1'
80
77
```
81
78
82
-
###
83
-
84
-
### Install libraries
79
+
## ✅ Install libraries
85
80
86
-
Python is an open-source software actively supported by a huge ecosystem where programmers expose their work to be reused by others. Flask and Django are just a few examples. The full-index with available packages can be found on [PyPI - Python Package Index](https://pypi.org/).
81
+
Python is an open-source software actively supported by a huge ecosystem where programmers expose their work to be reused by others.
82
+
Flask and Django are just a few examples. The full-index with available packages can be found on [PyPI - Python Package Index](https://pypi.org/).
87
83
88
84
In this section we will write code to extract the title from a web page. To do this, we will reuse two popular libraries putbished on **PyPI** and use them in the python console to extract the title from `google.com`.
89
85
@@ -94,8 +90,8 @@ $ pip install requests
94
90
$ pip install BeautifulSoup4
95
91
```
96
92
97
-
Once the libraries are installed succesfully, we can write code in the Python console.\
98
-
 Just for fun, we can **scan and extract the title** from `Google` site with a few lines of code:
93
+
Once the libraries are installed succesfully, we can write code in the Python console.
94
+
Just for fun, we can **scan and extract the title** from `Google` site with a few lines of code:
99
95
100
96
```python
101
97
>>>import requests # import the library
@@ -107,14 +103,141 @@ Once the libraries are installed succesfully, we can write code in the Python co
107
103
<title>Google</title>
108
104
```
109
105
110
-
### [Python Web Frameworks](https://hackr.io/blog/python-frameworks)
106
+
## ✅ Sample Programs
107
+
108
+
### Parse `Titanic.csv` data
109
+
110
+
If the CSV file is hosted online, you can still easily access and extract data from it using Python and the `pandas` library.
111
+
You can use the URL of the CSV file directly with `pd.read_csv()`.
112
+
113
+
> **Here's how to do it**:
114
+
115
+
1.**Install pandas**: If you haven't already installed pandas, you can do so using pip:
116
+
117
+
```bash
118
+
pip install pandas
119
+
```
120
+
121
+
2.**Import pandas**: Import the pandas library in your Python script.
122
+
123
+
```python
124
+
import pandas as pd
125
+
```
126
+
127
+
3.**Read the CSV file from the online source**: Use the `pd.read_csv()` function with the URL of the CSV file.
4.**Explore and analyze the data**: You can now work with the `titanic_data` DataFrame just like you would with a locally stored CSV file. You can perform various data analysis tasks on the data, such as filtering, grouping, plotting, and more.
135
+
136
+
Here's an example of how to display the first few rows of the dataset:
137
+
138
+
```python
139
+
print(titanic_data.head())
140
+
```
141
+
142
+
This will show you the first 5 rows of the dataset.
143
+
144
+
Make sure that the online CSV file is publicly accessible and that you have the necessary permissions to access it.
145
+
146
+
### Generate a PIE Chart
147
+
148
+
To access the Titanic dataset, categorize passengers into "Men," "Women," and "Child," and generate a pie chart, you can follow these steps using Python and the `pandas` and `matplotlib` libraries:
149
+
150
+
1.**Import necessary libraries**:
151
+
152
+
```python
153
+
import pandas as pd
154
+
import matplotlib.pyplot as plt
155
+
```
156
+
157
+
2.**Read the Titanic dataset from an online source (as shown in the previous answer)**.
158
+
159
+
3.**Categorize passengers**:
160
+
161
+
You can categorize passengers into "Men," "Women," and "Child" based on age and gender. For this example, let's consider passengers aged 18 or below as "Child." You can adjust this threshold as needed.
162
+
163
+
```python
164
+
# Create a new column 'Category' to store passenger categories
165
+
titanic_data['Category'] ='Adult'# Default category is 'Adult'
This code will create a pie chart showing the percentage distribution of passengers in the categories "Men," "Women," and "Child."
191
+
192
+
Make sure to adjust the age threshold and category definitions as needed for your analysis.
193
+
194
+
## ✅ Python Web Frameworks
195
+
196
+
A web framework, in the context of software development, is a pre-built collection of tools, libraries, and best practices designed to assist developers in building web applications, websites, or web services.
197
+
198
+
It provides a structured way to develop web applications by offering a set of reusable components and guidelines for common web development tasks. Web frameworks can be used to streamline the development process, improve code organization, and enhance the maintainability and scalability of web applications.
199
+
200
+
> Here is a short list with **popular frameworks for Python**
201
+
202
+
### [Django](https://www.djangoproject.com/)
203
+
204
+
Django is a leading web development framework written in Python.
205
+
206
+
Django framework follows the DRY (Don’t Repeat Yourself) principle and provides an impressive number of built-in features rather than offering them as individual libraries.
207
+
Django makes use of its ORM for mapping objects to database tables.
208
+
209
+
### [Flask](https://flask.palletsprojects.com/)
210
+
211
+
Flask allows the developers to build a solid web application foundation from where it is possible to use any kind of extensions required.
212
+
Inspired by the Sinatra Ruby framework, the microframework requires Jinja2 template and Werkzeug WSGI toolkit.
213
+
214
+
### [FastAPI](https://fastapi.tiangolo.com/)
215
+
216
+
FastAPI is a modern, high-performance, web framework for building APIs with Python. It's designed to be easy to use, efficient, and to provide automatic generation of interactive documentation.
217
+
FastAPI is built on top of Starlette and Pydantic, and it leverages Python 3.6+ type hints for request and response validation.
AIOHTTP is a Python framework that relies heavily on async & awaits Python capabilities.
222
+
In addition to being a server web framework, AIOHTTP can also serve as a client framework.
223
+
224
+
It provides a request object and router to enable the redirection of queries to functions developed to handle the same.
225
+
226
+
### [Bottle](https://bottlepy.org/docs/dev/)
227
+
228
+
Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. Here are the features:
229
+
230
+
-`Routing`: Requests to function-call mapping with support for clean and dynamic URLs.
231
+
-`Templates`: Fast and pythonic built-in template engine and support for mako, jinja2 and cheetah templates.
232
+
-`Utilities`: Convenient access to form data, file uploads, cookies, headers and other HTTP-related metadata.
233
+
-`Server`: Built-in HTTP development server and support for paste, bjoern, gae, cherrypy or any other WSGI capable HTTP server.
234
+
235
+
<br />
111
236
112
-
-[Flask](https://flask.palletsprojects.com/) - Available under the BSD license, Flask is another popular Python framework. Inspired by the Sinatra Ruby framework, the microframework requires Jinja2 library and Werkzeug WSGI toolkit.
113
-
-[Django](https://www.djangoproject.com/) - Full-stack framework Django is one of the most beloved web development frameworks for developing Python applications.
114
-
-[FastAPI](https://fastapi.tiangolo.com/) - a high performance, easy to learn, ready for production framework
237
+
## ✅ Resources
115
238
116
-
### Resources
239
+
- 👉 Access [AppSeed](https://appseed.us/) and start your next project
240
+
- 👉 [Deploy Projects on Aws, Azure and Digital Ocean](https://www.docs.deploypro.dev/) via **DeployPRO**
241
+
- 👉 Create an amazing landing page with [Simpllo, an open-source site builder](https://www.simpllo.com/)
0 commit comments