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
807
votes
10 answers

How to convert index of a pandas dataframe into a column

How to convert an index of a dataframe into a column? For example: gi ptt_loc 0 384444683 593 1 384444684 594 2 384444686 596 to index1 gi ptt_loc 0 0 384444683 593 1 1 …
msakya
  • 9,311
  • 5
  • 23
  • 31
400
votes
9 answers

Combining two Series into a DataFrame in pandas

I have two Series s1 and s2 with the same (non-consecutive) indices. How do I combine s1 and s2 to being two columns in a DataFrame and keep one of the indices as a third column?
user7289
  • 32,560
  • 28
  • 71
  • 88
393
votes
13 answers

Keep only date part when using pandas.to_datetime

I use pandas.to_datetime to parse the dates in my data. Pandas by default represents the dates with datetime64[ns] even though the dates are all daily only. I wonder whether there is an elegant/clever way to convert the dates to datetime.date or…
user1642513
199
votes
7 answers

Conditional Replace Pandas

I have a DataFrame, and I want to replace the values in a particular column that exceed a value with zero. I had thought this was a way of achieving this: df[df.my_channel > 20000].my_channel = 0 If I copy the channel into a new data frame it's…
BMichell
  • 3,581
  • 5
  • 23
  • 31
176
votes
6 answers

How to get the first column of a pandas DataFrame as a Series?

I tried: x=pandas.DataFrame(...) s = x.take([0], axis=1) And s gets a DataFrame, not a Series.
Yariv
  • 12,945
  • 19
  • 54
  • 75
169
votes
11 answers

Pandas: change data type of Series to String

I use Pandas 'ver 0.12.0' with Python 2.7 and have a dataframe as below: df = pd.DataFrame({'id' : [123,512,'zhub1', 12354.3, 129, 753, 295, 610], 'colour': ['black', 'white','white','white', 'black',…
Zhubarb
  • 11,432
  • 18
  • 75
  • 114
166
votes
8 answers

Convert pandas Series to DataFrame

I have a Pandas series sf: email email1@email.com [1.0, 0.0, 0.0] email2@email.com [2.0, 0.0, 0.0] email3@email.com [1.0, 0.0, 0.0] email4@email.com [4.0, 0.0, 0.0] email5@email.com [1.0, 0.0, 3.0] email6@email.com [1.0, 5.0,…
woshitom
  • 4,811
  • 8
  • 38
  • 62
153
votes
4 answers

Strings in a DataFrame, but dtype is object

Why does Pandas tell me that I have objects, although every item in the selected column is a string — even after explicit conversion. This is my DataFrame: Int64Index: 56992 entries, 0 to 56991 Data columns…
Xiphias
  • 4,468
  • 4
  • 28
  • 51
148
votes
8 answers

Convert pandas data frame to series

I'm somewhat new to pandas. I have a pandas data frame that is 1 row by 23 columns. I want to convert this into a series. I'm wondering what the most pythonic way to do this is? I've tried pd.Series(myResults) but it complains ValueError: cannot…
user1357015
  • 11,168
  • 22
  • 66
  • 111
142
votes
8 answers

Pandas selecting by label sometimes return Series, sometimes returns DataFrame

In Pandas, when I select a label that only has one entry in the index I get back a Series, but when I select an entry that has more then one entry I get back a data frame. Why is that? Is there a way to ensure I always get back a data frame? In…
Job Evers
  • 4,077
  • 5
  • 20
  • 26
127
votes
6 answers

Pandas: convert categories to numbers

Suppose I have a dataframe with countries that goes as: cc | temp US | 37.0 CA | 12.0 US | 35.0 AU | 20.0 I know that there is a pd.get_dummies function to convert the countries to 'one-hot encodings'. However, I wish to convert them to indices…
sachinruk
  • 9,571
  • 12
  • 55
  • 86
127
votes
1 answer

Get first element of Series without knowing the index

Is there any way to access the first element of a Series without knowing its index? Let's say I have the following Series: import pandas as pd key='MCS096' SUBJECTS = pd.DataFrame( { "ID": pd.Series([146], index=[145]), "study":…
Hello lad
  • 17,344
  • 46
  • 127
  • 200
122
votes
3 answers

Python: Pandas Series - Why use loc?

Why do we use 'loc' for pandas dataframes? it seems the following code with or without using loc both compile anr run at a simulular speed %timeit df_user1 = df.loc[df.user_id=='5561'] 100 loops, best of 3: 11.9 ms per loop or %timeit…
Runner Bean
  • 4,895
  • 12
  • 40
  • 60
114
votes
5 answers

Floor or ceiling of a pandas series in python?

I have a pandas series series. If I want to get the element-wise floor or ceiling, is there a built in method or do I have to write the function and use apply? I ask because the data is big so I appreciate efficiency. Also this question has not…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
101
votes
5 answers

Extract values in Pandas value_counts()

Say we have used pandas dataframe[column].value_counts() which outputs: apple 5 sausage 2 banana 2 cheese 1 How do you extract the values in the order same as shown above from max to min ? e.g: [apple,sausage,banana,cheese]
JamesButterlips
  • 1,021
  • 2
  • 8
  • 5
1
2 3
99 100