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

BUG: Set_index fills in some NaN #2850

Closed
hayd opened this issue Feb 12, 2013 · 6 comments
Closed

BUG: Set_index fills in some NaN #2850

hayd opened this issue Feb 12, 2013 · 6 comments
Labels
Milestone

Comments

@hayd
Copy link
Contributor

hayd commented Feb 12, 2013

In this example when setting the index of a DataFrame to columns with NaN this values is filled:

In [11]: df = pd.DataFrame({'id1': {0: '1a3', 1: '9h4'}, 'id2': {0: nan, 1: 'd67'},
                            'id3': {0: '78d', 1: '79d'}, 'value': {0: 123, 1: 64}})

In [12]: df
Out[12]: 
   id1  id2  id3  value
0  1a3  NaN  78d    123
1  9h4  d67  79d     64

In [13]: df.set_index(['id1', 'id2', 'id3'])
Out[13]: 
             value
id1 id2 id3       
1a3 d67 78d    123
9h4 d67 79d     64

I see this on '0.10.1.dev-f73128e', apologies if this has been mentioned before.
Note: This example is essentially from this SO question.

@ghost
Copy link

ghost commented Mar 14, 2013

jeff fixed this.

@ghost ghost closed this as completed Mar 14, 2013
@Marigold
Copy link

Unfortunately, if you specify append=True, the same thing happens.

df = pd.DataFrame({'id1': {0: '1a3', 1: '9h4'}, 'id2': {0: nan, 1: 'd67'}, 'id3': {0: '78d', 1: '79d'}, 'value': {0: 123, 1: 64}})
df.set_index(['id1', 'id2']).set_index('id3', append=True)

Output

             value
id1 id2 id3       
1a3 d67 78d    123
9h4 d67 79d     64

@jreback
Copy link
Contributor

jreback commented Dec 15, 2013

what version are u on?

this should be fixed on >= 0.11

@Marigold
Copy link

I'm on 0.12. It happens only with append=True, otherwise it's working fine.

@hayd
Copy link
Contributor Author

hayd commented Dec 16, 2013

@Marigold I confirm what you saw in 0.12, however it's fixed in master:

#master
In [10]: df.set_index(['id1', 'id2']).set_index('id3', append=True)
Out[10]: 
             value
id1 id2 id3       
1a3 NaN 78d    123
9h4 d67 79d     64

[2 rows x 1 columns]

I added in an additional test case for this.

@Marigold
Copy link

Confirm too. Thanks a lot.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants