Introduction to Pandas:Python Pandas library for data science(Part 1)
Tags: datascience, ai, python, pandas
Published: 2023-10-06 07:23:30

**What is Pandas?**
Pandas is a Python library designed for data manipulation and analysis. It simplifies various data-related tasks, making them more efficient and accessible. Whether you're working with datasets, performing data cleaning, exploration, or statistical analysis, Pandas provides the tools to help you achieve your goals.

**Why Use Pandas?**
Pandas offer numerous advantages for data scientists and analysts:
- Data Analysis: Pandas simplifies data analysis by providing powerful data structures and functions.
- Data Cleaning: It offers tools for cleaning and preprocessing data, such as handling missing values and outliers.
- Data Manipulation: Pandas allows you to reshape and transform data, making it suitable for your specific analysis needs.
- Readability: It enhances data readability through structured data frames and series.
- Simplified Workflow: Pandas streamlines data-related tasks, saving time and effort in data projects. For more in-depth information, you can explore resources like W3Schools,geeksforgeeks for more info.

**How to Install Pandas:**
You can easily install Pandas using the Python package manager, pip. Open your command prompt or terminal and run the following command:
```python
pip install pandas
```

**Usage:**
Once Pandas is installed, you can import it into your Python script or notebook using the alias 'pd':
```python
import pandas as pd
```
You can check the installed Pandas version with:
```python
print(pd.__version__)
```

**Pandas Series:**
A Pandas Series is a one-dimensional data structure representing a single column in a data frame. It is homogenous, meaning it contains elements of the same data type, and each element has a label (index). Here's an example:
```python
import pandas as pd

my_list = [30, 20, 23, 34]
my_series = pd.Series(my_list)
print(my_series)
```

**Pandas Labels:**
By default, Pandas assigns labels indexed from 0 to n-1, where n is the length of the series. However, you can customize the index as you prefer. Here's an example:
```python
custom_index = ['a', 'b', 'c', 'd', 'e']
my_new_series = pd.Series(my_list, index=custom_index)
print(my_new_series)
```
You can access a series item using its label, like this:
```python
print(my_new_series['a'])
```

**Key-Value Objects in Pandas Series:**
If you have a dictionary with key-value pairs, you can transform it into a Pandas Series. The keys will become the labels for the series.

**DataFrames:**
Pandas DataFrames are multidimensional tables with rows and columns. They can be thought of as collections of Pandas Series, and they are commonly used for structured data. Here's an example of creating a DataFrame from a dictionary:
```python
my_dict = {
    "name": ["Mike", "John"],
    "age": [12, 23]
}
new_df = pd.DataFrame(my_dict)
```
You can access specific rows using `.loc[]`. For example:
```python
new_df.loc["row_index"]
```
To access multiple rows, you can pass a list of indices:
```python
new_df.loc[[0, 1]]
```

You can also specify named indexes when creating the DataFrame by providing a list of indexes to the `index` argument.

When you need to load data from sources like CSV files, Excel files, or JSON files into a DataFrame, Pandas provides built-in functions like `pd.read_csv()`, `pd.read_excel()`, and `pd.read_json()` to simplify the process.


I will be showing you how to use the functions in the next article feel free to go ahead and do some research on your own, see you on the next one.