Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a series of numbers using Pandas in Python

Tags:

I am new to python and have recently learnt to create a series in python using Pandas. I can define a series eg: x = pd.Series([1, 2, 3, 4, 5]) but how to define the series for a range, say 1 to 100 rather than typing all elements from 1 to 100?

like image 679
MrCurious Avatar asked Apr 16 '16 17:04

MrCurious


People also ask

How do you write series in pandas?

You can create a series by calling pandas. Series() . An list, numpy array, dict can be turned into a pandas series. You should use the simplest data structure that meets your needs.

What is pandas Series Series?

A Pandas Series is like a column in a table. It is a one-dimensional array holding data of any type.

How can you create an empty series in pandas?

We can easily create an empty series in Pandas which means it will not have any value. The syntax that is used for creating an Empty Series: <series object> = pandas. Series()


1 Answers

As seen in the docs for pandas.Series, all that is required for your data parameter is an array-like, dict, or scalar value. Hence to create a series for a range, you can do exactly the same as you would to create a list for a range.

one_to_hundred = pd.Series(range(1,101)) 
like image 54
miradulo Avatar answered Oct 05 '22 13:10

miradulo