Teaser-5 (Create and display a one-dimensional)

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)

  1. 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 as pd, you can use pd as a shorthand to access pandas functions.
  2. 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.
  3. 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

Pandas Data Series: Create and display a one-dimensional array-like object containing an array of data using Pandas module – w3resource

Blogs – EducateNow Cafe

Leave a Reply