The pandas Series class has several attributes that describe a Series object.The ndim is the dimension which is always 1 for the Series.The shape tells the number of columns present in the Series.The index attribute denotes the range index of the Series.The nbytes describes the number of bytes of the data.
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
python
# 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
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
python
# 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
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
Your privacy choices
We'd like to use Google Analytics cookies to count visits and see which tutorials are useful.
They are only set if you accept. We don't use advertising cookies and we don't sell your data.
You can change your choice any time from “Your privacy choices” at the bottom of every page.
Privacy Policy
Your privacy choices
Your browser sent a Global Privacy Control signal, so analytics is off unless you turn it on here.
Strictly necessary
Remembers this choice in your browser. No cookies, nothing sent to anyone.Always on