Pandas Data Series: Create and display a one-dimensional array-like object containing an array of data
Pandas: Data Series Exercise-1 with Solution
Write a Pandas program to create and display a one-dimensional array-like object containing an array of data.
Sample Solution :
Python Code :
import pandas as pd
ds = pd.Series([2, 4, 6, 8, 10])
print(ds)
Sample Output:
0 2 1 4 2 6 3 8 4 10 dtype: int64
Explanation:
ds = pd.Series([2, 4, 6, 8, 10]): The code creates a Pandas Series object named 'ds' which contains a sequence of five integers: 2, 4, 6, 8, and 10.
print(ds): This line prints the contents of the Series object to the console.
The numbers on the left-hand side are the index of each value in the Series, which by default starts at 0 and increases by 1 for each subsequent element. The ‘dtype’ indicates the data type of the values in the Series, in this case, 64-bit integers.
Python-Pandas Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Python Pandas Data Series, DataFrame Exercises Home.
Next: Write a Pandas program to convert a Panda module Series to Python list and it’s type.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/pandas/python-pandas-data-series-exercise-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics