In this article “Introduction to Python with Anaconda and Pandas for Beginners,” you will be introduced to the fundamental steps required to begin your journey in Python programming using Anaconda and the essential Pandas package for data analysis.
Throughout this article, you will acquire the following skills:
- Installing the Anaconda distribution.
- Utilizing Jupyter Notebook.
- Creating your initial Python script within a notebook.
Moreover, you will also gain knowledge in the following areas:
- Python: understanding the foundational concepts necessary to start building proficiency.
- Pandas: exploring key methods for loading datasets, performing data description, making dataframe modifications, and performing computations.
Anaconda Install
On the official website of Anaconda, you will find how to install Anaconda for:
Subsequently, I will show you, step-by-step, how to create your first notebook.
How to create your first notebook?
Launch Anaconda
- In the Windows search area (bottom left), you can type anaconda.
- Click on Anaconda Navigator
- The final anaconda window will showed up (After some pop ups: either you accept or reject):
Launch Jupyter Notebook:
In this window, you will have all the tools integrated with Anaconda distribution.
The ones that could interest you, when working with Python are:
- Jupyter Notebook
- lab JupyterLab
- Spyder
The one I’m using all the time is Jupyter Notebook. I’ve tried the other ones, but this one is my favorite. You can choose the one that best fits your way of working.
Click on Launch:
A web page then opens, showing the whole locations of your pc:
For example, in Documents, I created a folder Python_Scripts, in which I put the whole work I’m doing in data science.
Go to the chosen folder you have decided to work in.
Once there, you can create either a folder or a Python script directly:
Create a folder:
- Once clicked on Folder, this line will appear:
- Tick it:
- Click on Rename:
- Choose a name:
- Click then on the folder:
Now you can create a Python script.
Create a notebook:
- Click on New, then Python 3:
- You have created your first Jupyter notebook:
- You can rename it, either:
- By ticking it and then rename it:
(you can also delete it or duplicate it)
- Or, by first clicking on the notebook. It will open a new window:
Click on Untitled and rename your notebook:
Execute a notebook
Once you write a line of code, like this one:
Either you press “Ctrl + Enter” or hit Execute:
Once executed, you will have a number of execution near to the cell:
Notice that the type of the cell per default is “Code”.
You can modify it to text if you want to write comments.
You can also run different groups of cells, or all cells. Go to Cell and choose the cells you want to run.
Useful Shortcuts
There are a lot of useful shortcuts that I use all the time, helping me do my job faster.
When you are in a cell:
- Esc + A : To insert a cell before the current one
- Esc + B : To insert a cell after the current one
- Esc + D D (twice a D): Delete the current cell
- Esc + 1: transforming a code cell to a title 1. (it adds one # in the cell)
- Then press Ctrl + Enter to validate the title:
- Esc + 2: transforming a code cell to a title 2. (it adds one ## in the cell)
…
You can add titles as many as you want until 4. After 5 it will be a comment.
Kernel
If you want to restart the kernel, or if you have trouble in executing your code, go there:
Bonus
There are many extensions to add to Jupyter notebooks that will make your life easier.
To add the Nbextensions tab to your Jupyter notebook, run these code lines in the command prompt or terminal:
pip install jupyter_contrib_nbextensions jupyter contrib nbextension install |
I added this extension in Jupyter notebook “Table of Contents”, to see more clearly the titles I have in my notebook:
You can have more information in this link.
Python – Basics
You can find, in the link below, a notebook in github which includes all the basics to know about Python:
- Data types,
- Variable assignments,
- Looping statements,
- Functions,
- List (how to create a list, accessing an element, slicing a list, adding an element…),
- Set,
- Dictionary
- …
There is a lot to be said, but if you are able to go through this notebook, you can learn the basics you need, to master your learning afterwards. https://github.com/MachineLearningBasics/Beginners_basics/blob/main/Python_basics.ipynb
Pandas
To be able to load datasets and analyse them, you must learn pandas.
Pandas is a very useful package that helps:
- Loading datasets,
- Analysing the type of data included in the datasets
- Giving statistical description of the data (mean, quantile 25, quantile 75, max, min…)
- Performing operations like grouping the data by column or different columns
- Computing the sum, average, standard deviation…
- Filtering the data on specific values
- Replacing the data
- Removing columns, rows
- Merging several data frames
- ….
Here is a detailed notebook to start with pandas, and learn the most useful functions:
https://github.com/MachineLearningBasics/Beginners_basics/blob/main/Must_Know_Pandas.ipynb
Summary
Throughout this Introduction To Python with Anaconda and Pandas for Beginners , you have gained proficiency in the following areas:
- Installing and launching Anaconda
- Creating your initial Jupyter notebook and executing code
- Grasping the fundamentals of Python programming
- Loading and analyzing datasets with the aid of Pandas
I hope you enjoyed reading my article. Leave me a comment, I will appreciate your feedbacks.