Questions tagged [series]

A Series object represents a data series. This may be represented as the SeriesCollection class (Java, C#) or Series class in Python Pandas.

  • A series is not necessarily plotted on a chart; it can store data point values that are used to perform a calculation from which another series is created and then plotted. More info available on MSDN.

  • This tag is also used in the context of questions on [pandas] Series. See the pandas tag wiki for more details.

Also see:

3544 questions
36
votes
1 answer

What is the fastest and most efficient way to append rows to a DataFrame?

I have a large dataset which I have to convert to .csv format, it consists of 29 columns and 1M+ lines. I figured that as the dataframe gets larger, appending any rows to it is getting more and more time consuming. I wonder if there is any faster…
Erdal Dogan
  • 557
  • 1
  • 4
  • 10
35
votes
1 answer

Python Reindex Producing Nan

Here is the code that I am working with: import pandas as pd test3 = pd.Series([1,2,3], index = ['a','b','c']) test3 = test3.reindex(index = ['f','g','z']) So originally every thing is fine and test3 has an index of 'a' 'b' 'c' and values 1,2,3.…
Adam Warner
  • 1,334
  • 2
  • 14
  • 30
35
votes
36 answers

Print series of prime numbers in python

I was having issues in printing a series of prime numbers from one to hundred. I can't figure our what's wrong with my code. Here's what I wrote; it prints all the odd numbers instead of primes: for num in range(1, 101): for i in range(2, num): …
user1546721
  • 363
  • 1
  • 4
  • 6
34
votes
2 answers

Check if a pandas Series has at least one item greater than a value

The following code will print True because the Series contains at least one element that is greater than 1. However, it seems a bit un-Pythonic. Is there a more Pythonic way to return True if a Series contains a number that is greater than a…
ChaimG
  • 7,024
  • 4
  • 38
  • 46
33
votes
2 answers

Create DataFrame from multiple Series

I have 2 Series, given by: import pandas as pd r = pd.Series([i*3 for i in range(0, 10)], name='rrr') s = pd.Series([i*5 for i in range(0, 10)], name='sss') How to I create a DataFrame from them?
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
33
votes
5 answers

How to create a series of numbers using Pandas in Python

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?
MrCurious
  • 333
  • 1
  • 3
  • 6
32
votes
7 answers

How to get maximum length of each column in the data frame using pandas python

I have a data frame where most of the columns are varchar/object type. Length of the column varies a lot and could be anything within the range of 3 - 1000+ . Now, for each column, I want to measure maximum length. I know how to calculate maximum…
singularity2047
  • 951
  • 4
  • 18
  • 28
32
votes
3 answers

From TimeDelta to float days in Pandas

I have a TimeDelta column with values that look like this: 2 days 21:54:00.000000000 I would like to have a float representing the number of days, let's say here 2+21/24 = 2.875, neglecting the minutes. Is there a simple way to do this ? I saw an…
alpagarou
  • 471
  • 2
  • 5
  • 11
31
votes
7 answers

How to specify the type of pandas series elements in type hints?

My function returns a pandas series, where all elements have a specific type (say str). The following MWE should give an impression: import pandas as pd def f() -> pd.Series: return pd.Series(['a', 'b']) Within the type hints I want to make…
Qaswed
  • 3,649
  • 7
  • 27
  • 47
30
votes
1 answer

What happens when you compare 2 pandas Series

I ran up against unexpected behavior in pandas when comparing two series. I wanted to know if this is intended or a bug. suppose I: import pandas as pd x = pd.Series([1, 1, 1, 0, 0, 0], index=['a', 'b', 'c', 'd', 'e', 'f'], name='Value') y =…
piRSquared
  • 285,575
  • 57
  • 475
  • 624
29
votes
1 answer

Sorting a pandas series

I am trying to figure out how to sort the Series generated as a result of a groupby aggregation in a smart way. I generate an aggregation of my DataFrame like this: means = df.testColumn.groupby(df.testCategory).mean() This results in a Series. I…
vasek1
  • 13,541
  • 11
  • 32
  • 36
28
votes
3 answers

KeyError: 0 when accessing value in pandas series

In my script I have df['Time'] as shown below. 497 2017-08-06 11:00:00 548 2017-08-08 15:00:00 580 2017-08-10 04:00:00 646 2017-08-12 23:00:00 Name: Time, dtype: datetime64[ns] But when i do t1=pd.Timestamp(df['Time'][0]) I get an…
Bharat Sharma
  • 1,081
  • 3
  • 11
  • 23
28
votes
3 answers

How to plot a bar graph from a pandas series?

Consider my series as below: First column is article_id and the second column is frequency count. article_id 1 39 2 49 3 187 4 159 5 158 ... 16947 14 16948 7 16976 2 16977 1…
Aashil
  • 427
  • 2
  • 5
  • 10
28
votes
12 answers

How do I find the millionth number in the series: 2 3 4 6 9 13 19 28 42 63 ...?

It takes about minute to achieve 3000 in my comp but I need to know the millionth number in the series. The definition is recursive so I cannot see any shortcuts except to calculate everything before the millionth number. How can you fast calculate…
hhh
  • 50,788
  • 62
  • 179
  • 282
27
votes
4 answers

Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13

I wrote a code that reads multiple files, however on some of my files datetime swaps day & month whenever the day is less than 13, and any day that is from day 13 or above i.e. 13/06/11 remains correct (DD/MM/YY). I tried to fix it by doing…
Oumab10
  • 696
  • 2
  • 6
  • 14