Sitemap
Dewi Safitri

Dewi Safitri

Passionate in Learning | Data Analytics | Bachelor of Biology Education. Linkedin : https://www.linkedin.com/in/dewi-safitri-a324331b5/

Python

5 min readAug 23, 2023

Python is a widely-used high-level programming language known for its versatility. Developed in the late 1980s, Python stands out due to its easily readable and understandable syntax. It supports object-oriented, functional, and procedural programming paradigms, making it suitable for a wide range of projects, from web development to data science, artificial intelligence, automation, and more.

WHY PYTHON?
— Easy to learn, especially for beginners.
— Clear and efficient syntax.
— An interpreted language, well-suited for dynamic programming (like data manipulation).
— Boasts an extensive ecosystem for both web development and data analysis.

Here are few important things about python:

  • Introduction to Notebooks: Notebooks (like Colab or Jupyter Notebook) harness Python’s capabilities as an interpreted language using a block-based coding system. This enables the dynamic execution of code block by block. Here’s an example.
Press enter or click to view image in full size
  • Python is capable of performing mathematical operations based on their priority from highest to lowest.
Press enter or click to view image in full size
  • Variables in programming are used to store data, information, or values. In Python, variables are assigned using the ‘=’ operator. In the example provided, the number 2 is assigned to the variable ‘value,’ and the word “Imam” is assigned to the variable ‘name.’ The ‘print()’ function is used to display variable contents in the console.
  • Here are the Data Types in Python.
  • Data Collection:
    In Python, data collections can be stored in forms like lists, tuples, sets, and dictionaries.
Press enter or click to view image in full size
  • Errors in Python:
    Below are examples of error messages in Python that indicate issues within the input script.
Press enter or click to view image in full size
  • Object Types in Python:
    Python is an object-oriented language. There are various object types in Python. Let’s start with the most common ones: strings, integers, and floats. Every time you work with text in Python, you’re using string objects. On the other hand, the most common numeric types are integers (e.g., -1, 0, 100) and floats, which represent real numbers (e.g., 3.14, -42.0).
Press enter or click to view image in full size

MINI TASK:
Create a comprehensive personal biodata using a dictionary, then attempt to retrieve and display your nickname using a key.

Get Dewi Safitri’s stories in your inbox

Join Medium for free to get updates from this writer.

Below are the script and the output for this task.

Working with Pandas:
Before starting the task, it’s essential to ensure the required module is imported. Here’s the script for it:

Next, we’ll import a dataset, which can be done through various methods.

Press enter or click to view image in full size

MINI TASK:
Question 1: Compare the number of immigrants from India and China from 1980 to 2013.

Step 1: Obtain the dataset for China and India, and display the data frame.
Below is the script and its output.

Press enter or click to view image in full size

Step 2: Plot the graph.

We’ll explicitly specify a line plot by passing the ‘kind’ parameter to ‘plot()’. Since ‘df_CI’ is a data frame with ‘Country’ as an index and years as columns, we need to transpose it using the ‘transpose()’ method to switch rows and columns before creating the graph.

Below is the script to create the graph based on the question, along with the output.

Press enter or click to view image in full size

Question 2: Compare the trend of the top 5 countries contributing the most to immigration to Canada.
Below is the script to answer this question.

Press enter or click to view image in full size

Here’s the requested graph.

Press enter or click to view image in full size

Python in Data Analysis:
In this section, we’ll explore some applications of Python in data analysis that we’ll practice.
1. Convert the Date column to Datetime type.
2. Create additional columns for day, month, and month number.
3. Filter by month and year.
4. Use ‘sort_values’.
5. Utilize ‘pivot_table’ and ‘groupby’.
6. Transform groupby output into a DataFrame.
7. Create and use simple functions on a DataFrame.
8. Generate simple visualizations using matplotlib.
9. Execute SQL in Colab using sqlite3.

Question 1: Display the top 5 cities during 2016 based on the highest profit values. Also, visualize the data using a bar chart.
Below is the script to display the top 5 cities and its output.

Press enter or click to view image in full size

Next, create a bar chart from the data.

Press enter or click to view image in full size

Below is the requested bar chart.

Press enter or click to view image in full size

--

--

Dewi Safitri
Dewi Safitri

Written by Dewi Safitri

Passionate in Learning | Data Analytics | Bachelor of Biology Education. Linkedin : https://www.linkedin.com/in/dewi-safitri-a324331b5/