A sequence of labels for the data. If None, a default integer index (0, 1, 2, ...) is assigned.
import pandas as pd
# Creating a Series
s = pd.Series(data=[10, 20, 30], index=['x', 'y', 'z'], name='Numbers')
print(s)
'''
Output:
x 10
y 20
z 30
Name: Numbers, dtype: int64
'''
If index is provided, it must always match with the length of the data.
Specifies the data-type of the Series. If not provided, it’s inferred from the input.
import pandas as pd
# Creating a Series
s = pd.Series(data=[10, 20, 30], index=['x', 'y', 'z'], dtype='int8', name='Numbers')
print(s)
'''
Output:
x 10
y 20
z 30
Name: Numbers, dtype: int8
'''
int8: 8-bit signed integer (range: -128 to 127).
int16: 16-bit signed integer (range: -32,768 to 32,767).
int32: 32-bit signed integer (range: -2,147,483,648 to 2,147,483,647).
int64: 64-bit signed integer (large integer range).
uint8: 8-bit unsigned integer (range: 0 to 255).
uint16: 16-bit unsigned integer (range: 0 to 65,535).
uint32: 32-bit unsigned integer (range: 0 to 4,294,967,295).
uint64: 64-bit unsigned integer (large positive integer range).
float16: Half precision floating-point (16-bit, for low-precision computations).
float32: Single precision floating-point (32-bit).
float64: Double precision floating-point (64-bit, the default float in NumPy).
float128: Extended precision floating-point (128-bit, availability depends on system).
complex64: Complex number represented by two 32-bit floats (for real and imaginary parts).
complex128: Complex number represented by two 64-bit floats (default complex dtype).
complex256: Complex number represented by two 128-bit floats (system-dependent).
bool: Boolean type, can be either True or False (stored as 1-bit but takes up a full byte).
str: Fixed-length Unicode string, specified by S + length (e.g., S10 for a 10-character string).
unicode: Fixed-length Unicode string with support for multiple characters (uses U).
object: Allows storing any Python object, including mixed types, strings, or other arrays. Useful for heterogeneous data but slower than native NumPy types.
datetime64: Stores dates and times with varying precisions (e.g., Y, M, D, h, m, s, ms, us, ns, ps, fs, as). Example: datetime64('2003-10-02')
timedelta64: Represents time durations with units (same units as datetime64).
If True, a copy of the input data is created. This is useful if you want to ensure the original data remains unchanged.
Changes to the new array will also affect the original array.
import pandas as pd
import numpy as np
# Original data as a NumPy array
original_data = np.array([1, 2, 3])
# Create a Series using the NumPy array
s = pd.Series(data=original_data, copy=False)
# Modify the original data (this will affect the Series)
original_data[0] = 100
# Print the Series
print(s)
'''
Output:
0 100
1 2
2 3
dtype: int64
'''
A new Series is created, and the data is copied.
import pandas as pd
import numpy as np
# Original data as a NumPy array
original_data = np.array([1, 2, 3])
# Create a Series using the NumPy array
s = pd.Series(data=original_data, copy=True)
# Modify the original data (this will *not* affect the Series)
original_data[0] = 100
# Print the Series
print(s)
'''
Output:
0 1
1 2
2 3
dtype: int64
'''
copy is handy only when the data is of the type np.ndarray.
Modification to the original_array or new_array will affect both the arrays.
Refer to numpy documentation.
An internal parameter used to optimize Series creation.