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
58
votes
3 answers

assigning column names to a pandas series

I have a pandas series object x Ezh2 2 Hmgb 7 Irf1 1 I want to save this as a dataframe with column names Gene and Count respectively I tried x_df = pd.DataFrame(x,columns = ['Gene','count']) but it does not work.The final form I want…
Ssank
  • 3,367
  • 7
  • 28
  • 34
57
votes
14 answers

Elegant way to remove items from sequence in Python?

When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is…
postfuturist
  • 22,211
  • 11
  • 65
  • 85
57
votes
6 answers

How to get the number of the most frequent value in a column?

I have a data frame and I would like to know how many times a given column has the most frequent value. I try to do it in the following way: items_counts = df['item'].value_counts() max_item = items_counts.max() As a result I get: ValueError:…
Roman
  • 124,451
  • 167
  • 349
  • 456
54
votes
3 answers

how to convert pandas series to tuple of index and value

I'm looking for an efficient way to convert a series to a tuple of its index with its values. s = pd.Series([1, 2, 3], ['a', 'b', 'c']) I want an array, list, series, some iterable: [(1, 'a'), (2, 'b'), (3, 'c')]
piRSquared
  • 285,575
  • 57
  • 475
  • 624
53
votes
3 answers

Remove name, dtype from pandas output of dataframe or series

I have output file like this from a pandas function. Series([], name: column, dtype: object) 311 race 317 gender Name: column, dtype: object I'm trying to get an output with just the second column, i.e., race gender by deleting top and…
pam
  • 1,175
  • 5
  • 15
  • 28
52
votes
5 answers

Sort dataframe by string length

I want to sort by name length. There doesn't appear to be a key parameter for sort_values so I'm not sure how to accomplish this. Here is a test df: import pandas as pd df = pd.DataFrame({'name': ['Steve', 'Al', 'Markus', 'Greg'], 'score': [2, 4, 2,…
Alex
  • 12,078
  • 6
  • 64
  • 74
49
votes
4 answers

Convert Pandas series containing string to boolean

I have a DataFrame named df as Order Number Status 1 1668 Undelivered 2 19771 Undelivered 3 100032108 Undelivered 4 2229 Delivered 5 00056 Undelivered I would like to convert the Status column to…
working4coins
  • 1,997
  • 3
  • 22
  • 30
46
votes
2 answers

Delete rows if there are null values in a specific column in Pandas dataframe

I'm new to python pandas. Need some help with deleting a few rows where there are null values. In the screenshot, I need to delete rows where charge_per_line == "-" using python pandas.
kumar
  • 629
  • 1
  • 6
  • 9
46
votes
3 answers

Pandas filtering for multiple substrings in series

I need to filter rows in a pandas dataframe so that a specific string column contains at least one of a list of provided substrings. The substrings may have unusual / regex characters. The comparison should not involve regex and is case…
jpp
  • 159,742
  • 34
  • 281
  • 339
46
votes
10 answers

Pandas Series of lists to one series

I have a Pandas Series of lists of strings: 0 [slim, waist, man] 1 [slim, waistline] 2 [santa] As you can see, the lists vary by length. I want an…
Max
  • 837
  • 4
  • 11
  • 20
41
votes
4 answers

Pandas reset index on series to remove multiindex

I have a Series that looks like this: 1999-03-31 SOLD_PRICE NaN 1999-06-30 SOLD_PRICE NaN 1999-09-30 SOLD_PRICE NaN 1999-12-31 SOLD_PRICE 3.00 2000-03-31 SOLD_PRICE 3.00 with an index that looks like: MultiIndex [(1999-03-31…
dartdog
  • 10,432
  • 21
  • 72
  • 121
39
votes
1 answer

Pandas pd.Series.isin performance with set versus array

In Python generally, membership of a hashable collection is best tested via set. We know this because the use of hashing gives us O(1) lookup complexity versus O(n) for list or np.ndarray. In Pandas, I often have to check for membership in very…
jpp
  • 159,742
  • 34
  • 281
  • 339
38
votes
1 answer

Pandas mask / where methods versus NumPy np.where

I often use Pandas mask and where methods for cleaner logic when updating values in a series conditionally. However, for relatively performance-critical code I notice a significant performance drop relative to numpy.where. While I'm happy to accept…
jpp
  • 159,742
  • 34
  • 281
  • 339
37
votes
4 answers

how to convert a Series of arrays into a single matrix in pandas/numpy?

I somehow got a pandas.Series which contains a bunch of arrays in it, as the s in the code below. data = [[1,2,3],[2,3,4],[3,4,5],[2,3,4],[3,4,5],[2,3,4], [3,4,5],[2,3,4],[3,4,5],[2,3,4],[3,4,5]] s = pd.Series(data = data) s.shape # output…
user3768495
  • 4,077
  • 7
  • 32
  • 58
37
votes
3 answers

Is there a query method or similar for pandas Series (pandas.Series.query())?

The pandas.DataFrame.query() method is of great usage for (pre/post)-filtering data when loading or plotting. It comes particularly handy for method chaining. I find myself often wanting to apply the same logic to a pandas.Series, e.g. after having…
dmeu
  • 3,842
  • 5
  • 27
  • 43