5. Program to create and display a one-dimensional array-like object containing an array of data.
import pandas as pd
ds = pd.Series([3, 5, 7, 9, 11])
print(ds)
-
Importing pandas:
import pandas as pd
- This line imports the
pandas
library, which is a powerful tool for data manipulation and analysis in Python. By importing it aspd
, you can usepd
as a shorthand to access pandas functions.
- This line imports the
-
Creating a Series:
ds = pd.Series([3, 5, 7, 9, 11])
- Here, you’re creating a Series object using pandas. A Series is like a column in a table. It’s a one-dimensional array that can hold data of any type. In this case, you’re creating a Series with the numbers 3, 5, 7, 9, and 11.
-
Printing the Series:
print(ds)
- This line prints the Series to the console. When you run this code, you’ll see the numbers 3, 5, 7, 9, and 11 displayed in a column format, along with their corresponding index numbers (0, 1, 2, 3, 4).
Here’s what the output will look like:
0 3
1 5
2 7
3 9
4 11
dtype: int64