Skip to content

Commit 417cb1f

Browse files
committed
UPD - What IS Python
1 parent 8600f0c commit 417cb1f

File tree

1 file changed

+152
-29
lines changed

1 file changed

+152
-29
lines changed

docs/content/what-is/python.mdx

Lines changed: 152 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
---
2-
sidebar_position: 15
3-
description: Short introduction to Python
2+
title : What IS Python
3+
sidebar_label : What IS Python
44
---
55

66
# What IS Python
77

8-
<SubHeading> Short introduction to Python</SubHeading>
8+
<SubHeading>Short introduction to Python</SubHeading>
99

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.
1112

12-
- [Python](https://www.python.org/) - the official website
13-
- [Python For Beginners](https://www.python.org/about/gettingstarted/) - a starting guide &#x20;
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&#x20;
13+
Python is interpreted, easy to learn surrounded by a huge ecosystem, actively supported and used in many industries and domains.
1614

17-
**Can be used for things like**: (starting from the simple ones)
15+
> **Can be used for things like**: (starting from the simple ones)
1816
1917
- Basic programming: using strings, adding numbers, open files
2018
- Writing system scripts (creating instructions that tell a computer system to “do” something)
2119
- Back end (or server-side) web and mobile app development
2220
- Desktop apps and software development
2321
- Processing big data and performing mathematical computations
2422

25-
### Install Python
23+
## [Install Python](/technologies/python/how-to-install/)
2624

27-
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:
2827

2928
```bash
3029
$ python --version
31-
Python 3.7.2
30+
Python 3.9.12
3231
```
3332

34-
###
35-
36-
### Coding in Python
33+
## ✅ Coding in Python
3734

3835
To start using Python we need to open a terminal, type `python` and we should be see the python console waiting for input.
3936

@@ -79,11 +76,10 @@ TypeError: can only concatenate str (not "int") to str
7976
'text 1'
8077
```
8178

82-
###
83-
84-
### Install libraries
79+
## ✅ Install libraries
8580

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/).
8783

8884
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`.
8985

@@ -94,8 +90,8 @@ $ pip install requests
9490
$ pip install BeautifulSoup4
9591
```
9692

97-
Once the libraries are installed succesfully, we can write code in the Python console. \
98-
&#x20;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:
9995

10096
```python
10197
>>> import requests # import the library
@@ -107,14 +103,141 @@ Once the libraries are installed succesfully, we can write code in the Python co
107103
<title>Google</title>
108104
```
109105

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.
128+
129+
```python
130+
url = 'https://github.com/datasciencedojo/datasets/blob/master/titanic.csv'
131+
titanic_data = pd.read_csv(url)
132+
```
133+
134+
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'
166+
167+
# Categorize passengers based on age and gender
168+
titanic_data.loc[(titanic_data['Age'] <= 18) & (titanic_data['Sex'] == 'male'), 'Category'] = 'Child'
169+
titanic_data.loc[(titanic_data['Age'] <= 18) & (titanic_data['Sex'] == 'female'), 'Category'] = 'Child'
170+
titanic_data.loc[titanic_data['Sex'] == 'female', 'Category'] = 'Women'
171+
```
172+
173+
4. **Generate a pie chart**:
174+
175+
You can create a pie chart to visualize the distribution of passengers in these categories.
176+
177+
```python
178+
# Count the number of passengers in each category
179+
category_counts = titanic_data['Category'].value_counts()
180+
181+
# Create a pie chart
182+
plt.figure(figsize=(6, 6))
183+
plt.pie(category_counts, labels=category_counts.index, autopct='%1.1f%%', startangle=140)
184+
plt.title('Passenger Distribution by Category')
185+
186+
# Display the pie chart
187+
plt.show()
188+
```
189+
190+
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.
218+
219+
### [AIOHTTP](https://docs.aiohttp.org/en/stable/)
220+
221+
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 />
111236

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
115238

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/)
242+
- 👉 [Django App Generator](https://app-generator.dev/django/) - A 2nd generation App Builder
117243

118-
- [Flask Dashboards](http://appseed.us/admin-dashboards/flask) - provided by AppSeed
119-
- [Django Dashboards](http://appseed.us/admin-dashboards/django) - a curated list
120-
- Join [AppSeed](https://appseed.us) - For support and `production-ready` starters&#x20;

0 commit comments

Comments
 (0)