Tuesday, 15 August 2023

Pandas: A series can hold any type of data

Example 1: Series of integer values

primes_series = pd.Series([2, 3, 5, 7])

 

Example 2: Series of boolean values

boolean_series = pd.Series([True, False, False, True])
 

Example 3: Series of mixed values

mixed_series = pd.Series(['Hi', 2, True, 5.67])

 


series_can_hold_any_type_of_data.py

import pandas as pd

# Series of integer values
primes_series = pd.Series([2, 3, 5, 7])

# Series of boolean values
boolean_series = pd.Series([True, False, False, True])

# Series of mixed values
mixed_series = pd.Series(['Hi', 2, True, 5.67])

print('\nprimes_series\n',primes_series)
print('\nboolean_series\n',boolean_series)
print('\nmixed_series\n',mixed_series)

 

Output

primes_series
 0    2
1    3
2    5
3    7
dtype: int64

boolean_series
 0     True
1    False
2    False
3     True
dtype: bool

mixed_series
 0      Hi
1       2
2    True
3    5.67
dtype: object

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment