Unique DataFrame using ONLY index

This is the place for queries that don't fit in any of the other categories.

Unique DataFrame using ONLY index

Postby tnknepp » Wed Sep 25, 2013 2:40 pm

Can I "uniquify" a dataframe only according to the index (i.e. not caring about the column values)?

Code: Select all
import pandas as pd
a = pd.DataFrame(data=[1,2,3,4,5],columns=['A'])
a = pd.concat([a,a*100])

# This has all unique values in a.A, but the index is not unique
>>> a
     A
0    1
1    2
2    3
3    4
4    5
0  100
1  200
2  300
3  400
4  500


Normally, I would use: a = a.drop_duplicates() to make the dataframe unique, but that doesn't work here. Any ideas on how to make this work without creating a new column (based off the index)?
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
tnknepp
 
Posts: 119
Joined: Mon Mar 11, 2013 7:41 pm

Re: Unique DataFrame using ONLY index

Postby Kebap » Thu Sep 26, 2013 10:09 am

Code: Select all
>>> import pandas
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ImportError: No module named pandas


Sorry, I can't help you.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 365
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests