Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the name parameter in Pandas Series?

Tags:

In the doc of Series, the use parameter of name and fastpath is not explained. What do they do?

like image 634
Sounak Avatar asked Jul 08 '15 12:07

Sounak


People also ask

What is name of series in pandas?

The name of a Series becomes its index or column name if it is used to form a DataFrame. It is also used whenever displaying the Series using the interpreter. Returns label (hashable object) The name of the Series, also the column name if part of a DataFrame. See also Series.rename.

Does pandas series have column name?

A pandas Series has no column labels, as it is just a single column of a DataFrame . A Series does have row labels.

How do you name the pandas Series index?

You can use the rename() method of pandas. DataFrame to change column/index name individually. Specify the original name and the new name in dict like {original name: new name} to columns / index parameter of rename() . columns is for the column name, and index is for the index name.


1 Answers

The name argument allows you to give a name to a Series object, i.e. to the column. So that when you'll put that in a DataFrame, the column will be named according to the name parameter.

example:

In [1]: s = pd.Series(["A","B","C"], name="foo")  In [2]: s Out[2]:  0    A 1    B 2    C Name: foo, dtype: object  In [3]: pd.DataFrame(s) Out[4]:    foo 0   A 1   B 2   C 

If you don't give a name to your Series it will be named automatically. Here it will be a 0 in the dataframe object:

   0 0  A 1  B 2  C 

For the fastpath, it's an internal parameter and an issue has already been reported :

https://github.com/pydata/pandas/issues/6903

like image 141
jrjc Avatar answered Sep 30 '22 17:09

jrjc