Overview:
- The pandas Series object is suitable for storing and processing large amount of 1-dimensional time-series data in-memory.
- The elements of the Series instance can be of different types making the Series a heterogeneous container.
- The Series class is equipped with lot of methods to perform - binary operations on Series instances, computations on Series instances, plotting of various graphs using the data from the Series. It also has several attributes that define the Series instance.
- Those attributes can be classified into
- General, Dimension, Shape related
- Data related
- Memory-usage related
Example - General, dimension and shape related attributes of Pandas Series:
# Example Python program that prints the # name, dimension, shape and index of the series import pandas as pds
# Price quote of a stock quote = [1576588672, 12, "SCRIPNAME", 45.6, 44.9, 47.9, 44.8, 45.8, 452189];
# Create a Pandas Series series = pds.Series(quote, name="quote");
# Print attributes print("Dimension of the Series:%s"%series.ndim); print("Shape of the Series:%s"%series.shape); print("Name of the Series:%s"%series.name); print("Index of the Series:%s"%series.index); |
Output:
Dimension of the Series:1 Shape of the Series:9 Name of the Series:quote Index of the Series:RangeIndex(start=0, stop=9, step=1) |
Example - Series attributes related to its data, transpose of the data, data type of elements and memory usage:
# Example Python program that prints the size and memory related # attributes of a pandas Series import pandas as pds
hourlyTemperature = [65, 66, 67, 68, 67, 66, 65, 62, 60, 59, 55, 57]; series = pds.Series(data=hourlyTemperature);
print("The Series:%s"%series.values); print("The type of Series elements:%s"%series.dtype); print("Number of elements present in the Series:%s"%series.size); print("Number of bytes:%s"%series.nbytes); print("Number of actual bytes in memory:%s"%series.memory_usage()); print("The transpose of the series:") print(series.T); |
Output:
The Series:[65 66 67 68 67 66 65 62 60 59 55 57] The type of Series elements:int64 Number of elements present in the Series:12 Number of bytes:96 Number of actual bytes in memory:224 The transpose of the series: 0 65 1 66 2 67 3 68 4 67 5 66 6 65 7 62 8 60 9 59 10 55 11 57 dtype: int64 |