Skip to content

Commit 406004d

Browse files
authored
Merge pull request animator#207 from Santhosh-Siddhardha/main
Added Pandas Series Vs NumPy ndarray section under Pandas Module
2 parents 5ce1793 + 950a313 commit 406004d

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

contrib/pandas/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# List of sections
22

3-
- [Section title](filename.md)
3+
- [Pandas Series Vs NumPy ndarray](pandas_series_vs_numpy_ndarray.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Pandas Series Vs NumPy ndarray
2+
3+
NumPy ndarray and Pandas Series are two fundamental data structures in Python for handling and manipulating data. While they share some similarities, they also have distinct characteristics that make them suitable for different tasks.
4+
5+
Both NumPy ndarray and Pandas Series are essential tools for data manipulation in Python, Choosing between them depends on the nature of your data and the specific tasks you need to perform.
6+
7+
## NumPy ndarray
8+
9+
NumPy is short form for Numerical Python, provides a powerful array object called `ndarray`, It is very important for many scientific and mathematical Python libraries. ndarray is also called n-dimensional array. Indexing in ndarray is integer based indexing (like arr[0], arr[3], etc.).
10+
11+
Features of NumPy `ndarray`:
12+
13+
- **Homogeneous Data**: All elements in a NumPy array are of the same data type, which allows for efficient storage and computation.
14+
- **Efficient Computation and Performance**: NumPy arrays are designed for numerical operations and are highly efficient. They support vectorized operations, allowing you to perform operations on entire arrays rather than individual elements.
15+
- **Multi-dimensional**: NumPy arrays can be multi-dimensional, making them suitable for representing complex numerical data structures like matrices and n-dimensional arrays.
16+
17+
Example of creating a NumPy array:
18+
19+
```python
20+
import numpy as np
21+
22+
narr = np.array(['A', 'B', 'C', 'D', 'E'])
23+
print(narr)
24+
```
25+
Output:
26+
```python
27+
['A' 'B' 'C' 'D' 'E']
28+
```
29+
### Usage of NumPy ndarray:
30+
31+
- When you need to perform mathematical operations on numerical data.
32+
- When you’re working with multi-dimensional data.
33+
- When computational efficiency is important.
34+
- When you need to store data of same data type.
35+
36+
## Pandas Series
37+
38+
Pandas is a Python library used for data manipulation and analysis, introduces the `Series` data structure, which is designed for handling labeled one-dimensional data efficiently. Indexing in Pandas Series is Label-based. It effectively handles heterogeneous data.
39+
40+
Features of Pandas `Series`:
41+
42+
- **Labeled Data**: Pandas Series associates a label (or index) with each element of the array, making it easier to work with heterogeneous or labeled data.
43+
44+
- **Heterogeneous Data**: Unlike NumPy arrays, Pandas Series can hold data of different types (integers, floats, strings, etc.) within the same object.
45+
46+
- **Data Alignment**: One of the powerful features of Pandas Series is its ability to automatically align data based on label.
47+
48+
Example of creating a Pandas Series:
49+
50+
```python
51+
import pandas as pd
52+
53+
series = pd.Series([1,'B', 5, 7, 6, 8], index = ['a','b','c','d','e','f'])
54+
print(series)
55+
```
56+
Output:
57+
```python
58+
a 1
59+
b B
60+
c 5
61+
d 7
62+
e 6
63+
f 8
64+
dtype: object
65+
```
66+
67+
### Usage of Pandas Series:
68+
69+
- When you need to manipulate and analyze labeled data.
70+
- When you’re dealing with heterogeneous data or missing values.
71+
- When you need more high-level, flexible data manipulation functions.
72+
- When you are dealing with One-dimensional data.

0 commit comments

Comments
 (0)