Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series name information is lost when doing DataFrame.apply() #983

Closed
lbeltrame opened this issue Mar 30, 2012 · 6 comments

Comments

@lbeltrame
Copy link
Contributor

commented Mar 30, 2012

On both axes, the generated Series on which the function has to work lack the "name" attribute (either the row name or th column name).

@lbeltrame

This comment has been minimized.

Copy link
Contributor Author

commented Mar 30, 2012

I tested this on a non-mixed type DataFrame, I'm unsure in the case of mixed-types.

@lodagro

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2012

see als mailing list discussion

@wesm wesm closed this in cb730a7 Apr 10, 2012

@wesm

This comment has been minimized.

Copy link
Member

commented Apr 10, 2012

it's a done deal

@lbeltrame

This comment has been minimized.

Copy link
Contributor Author

commented Apr 10, 2012

Unfortunately, there are still some issues. When doing axis=1, the name is preserved only in the first iteration (or not preserved at all in some cases): I checked by using a function that only prints out the Series out and returns the same series and after the first iteration, name information is lost.

The behavior is more consistent with axis=0.

In [17]: df = pandas.DataFrame(index=["A", "B", "C"],
                               data={"Foo": [1,2,3],  "Bar": [5,6,7], 
                                     "Baz":[8, 9, 10]})

In [18]: def foo(x):
    print x.name
    return x
   ....: 

In [19]: df.apply(foo, axis=1)
None
None
None
Out[19]: 
   Bar  Baz  Foo
A    5    8    1
B    6    9    2
C    7   10    3

In [20]: df.apply(foo, axis=0)
Bar
Baz
Foo
Out[20]: 
   Bar  Baz  Foo
A    5    8    1
B    6    9    2
C    7   10    3
@wesm

This comment has been minimized.

Copy link
Member

commented Apr 10, 2012

You're right-- I only fixed it in the reduction code. I'll take another look

@wesm

This comment has been minimized.

Copy link
Member

commented Apr 10, 2012

OK, fixed this and added tests. looks OK now

@wesm wesm closed this Apr 10, 2012

yarikoptic added a commit to neurodebian/pandas that referenced this issue Apr 12, 2012
Merge commit 'v0.7.2-111-gf7b9139' into debian
* commit 'v0.7.2-111-gf7b9139': (178 commits)
  DOC: refer to pydata@googlegroups.com instead of pystatsmodels@googlegroups.com
  DOC: fix url to vbench moved over to pydata
  DOC: some docs re: Panel.from_dict with orient='minor', close pandas-dev#1009
  ENH: use filtered exog index for the y_predict result, per pandas-dev#1027 close pandas-dev#1008
  ENH: make method signature more consistent with new statsmodels behavior. Uses dot product directly so pandas users aren't affected by statsmodels API change
  ENH: added OLS.predict method; pass through call to statsmodels ols predict method
  DOC: encoding affects python 2 and 3
  DOC: read_fwf doc tweaks for 0.7.3
  Sphinx documentation for read_fwf
  DOC: add what's new for 0.7.3, some scatter_matrix improvements
  TST: python 3 fixes
  BUG: return ax.get_figure() in scatter_plot if ax argument is not None
  add ax kwd to several functions and push ax into subplots so new subplot axes is generated on the ax's figure
  ENH: label sizes and rotations for histogram TST: test cases for both Series and DataFrame histogram
  DOC: all 0.7.3 issues should now be in either new features or bug fixes
  ENH: partial multiple setting on first level via .ix on DataFrame, close pandas-dev#409
  RLS: python 2.5 compatibility stuff with boolean arrays
  BUG: treat None as NA in DataFrame arithmetic operations, pandas-dev#992
  BUG: fix indexing error when selecting section of a hierarchically-indexed DataFrame row, close pandas-dev#1013
  ENH: attach name to Series on axis=1 in DataFrame.apply, pandas-dev#983
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.