You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However mapping a function on the index means modifying an existing index, so one would expect the name of the index to stay the same as opposed to when choosing a completely new index.
Output of pd.show_versions()
python: 2.7.12.final.0
pandas: 0.19.0
EDIT:
Doing a set_index(column) does NOT set the column name as the index name, I think it would be common sense that the name of the column which becomes the new index be automatically set as the index name.
The text was updated successfully, but these errors were encountered:
This is indeed because of #12766. The Index.map returns an array, which does not hold the index name. So setting the index to that array, will result in an index without name.
The fix here is to have Index.map return an Index, which can keep the original name -> #12766
Regarding your other question, set_index does use the column name for the index name:
In [43]: df = pd.DataFrame({'a':[1,2,3], 'b': [4,5,6]})
In [44]: df
Out[44]:
a b
0 1 4
1 2 5
2 3 6
In [45]: df.set_index('a')
Out[45]:
b
a
1 4
2 5
3 6
In [46]: df.set_index('a').index.name
Out[46]: 'a'
In [47]: df.set_index(df['a']).index.name
Out[47]: 'a'
Do you have an example where this is not the case?
Uh oh!
There was an error while loading. Please reload this page.
This is related to #12766
Possibly a duplicate.
A small, complete example of the issue
Expected Output
The mapping operation deletes the index name.
However mapping a function on the index means modifying an existing index, so one would expect the name of the index to stay the same as opposed to when choosing a completely new index.
Output of
pd.show_versions()
EDIT:
Doing a
set_index(column)
does NOT set the column name as the index name, I think it would be common sense that the name of the column which becomes the new index be automatically set as the index name.The text was updated successfully, but these errors were encountered: