Skip to content

Commit f877018

Browse files
Update Pandas_Series_Vs_NumPy_ndarray.md
Added Output for Code Snippets
1 parent 33bae7b commit f877018

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

contrib/pandas/Pandas_Series_Vs_NumPy_ndarray.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
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.
44

5-
While 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.
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.
66

7-
## NumPy ndarray (n-dimensional array)
7+
## NumPy ndarray
88

9-
NumPy is short form for Numerical Python, provides a powerful array object called `ndarray`, which is the backbone of many scientific and mathematical Python libraries.
9+
NumPy is short form for Numerical Python, provides a powerful array object called `ndarray`, which is the backbone of many scientific and mathematical Python libraries. ndarray is also called n-dimensional array. Indexing in ndarray is integer based indexing.
1010

11-
Here are key points about NumPy `ndarray`:
11+
Features of NumPy `ndarray`:
1212

1313
- **Homogeneous Data**: All elements in a NumPy array are of the same data type, which allows for efficient storage and computation.
14-
- **Efficient Computation**: 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 tensors.
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.
1616

1717
Example of creating a NumPy array:
1818

@@ -22,21 +22,26 @@ import numpy as np
2222
narr = np.array(['A', 'B', 'C', 'D', 'E'])
2323
print(narr)
2424
```
25-
### Use NumPy ndarray:
25+
Output:
26+
```python
27+
['A' 'B' 'C' 'D' 'E']
28+
```
29+
### Usage of NumPy ndarray:
2630

2731
- When you need to perform mathematical operations on numerical data.
2832
- When you’re working with multi-dimensional data.
2933
- When computational efficiency is important.
34+
- When you need to store data of same data type. `
3035

3136
## Pandas Series
3237

33-
Pandas, built on top of NumPy, introduces the `Series` data structure, which is designed for handling labeled one-dimensional data efficiently.
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.
3439

35-
Here are the key points about Pandas `Series`:
40+
Features of Pandas `Series`:
3641

3742
- **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.
3843

39-
- **Flexible Data Types**: Unlike NumPy arrays, Pandas Series can hold data of different types (integers, floats, strings, etc.) within the same object.
44+
- **Heterogeneous Data**: Unlike NumPy arrays, Pandas Series can hold data of different types (integers, floats, strings, etc.) within the same object.
4045

4146
- **Data Alignment**: One of the powerful features of Pandas Series is its ability to automatically align data based on label. This makes handling and manipulating data much more intuitive and less error-prone.
4247

@@ -45,12 +50,23 @@ Example of creating a Pandas Series:
4550
```python
4651
import pandas as pd
4752

48-
series = pd.Series([1, 3, 5, 7, 6, 8])
53+
series = pd.Series([1,'B', 5, 7, 6, 8], index = ['a','b','c','d','e','f'])
4954
print(series)
5055
```
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+
```
5166

52-
### Use Pandas Series:
67+
### Usage of Pandas Series:
5368

5469
- When you need to manipulate and analyze labeled data.
5570
- When you’re dealing with heterogeneous data or missing values.
5671
- When you need more high-level, flexible data manipulation functions.
72+
- When you are dealing with One-dimensional data.

0 commit comments

Comments
 (0)