1

I have a dataframe that looks like this

CompanyName User Issue  Equipment Issue No  TBD Total
Customer1   0   0   35  0   35
Customer2   0   0   28  0   28
Customer3   2   3   12  0   17
Customer4   5   1   8   0   14

I want to remove Customer1 and Customer2 from the table. I am trying to use

df= df[[c for c in df.columns if c not in ['Customer1','Customer2']]]

and

df=df[(~df.isin('Customer2','Customer2'))]

and

df=df[~df['CompanyName'].str.contains('Customer1')]

I'm not getting any errors, but Customer1 and Customer2 are still showing up in the plot!

df.columns.tolist

Out[85]: <bound method Index.tolist of Index([u'CompanyName', u'User Issue', u'Equipment Issue', u'No', u'TBD'], dtype='object')>

sortedtotal.columns.tolist()
Out[93]: 
['CompanyName',
 'User Issue',
 'Equipment Issue',
 'No',
 'TBD']
4
  • Is it your index? if so then df.loc[~df.index.isin(['Customer1','Customer2'])] should work, also show the output from df.columns.tolist() Commented Jul 13, 2015 at 15:50
  • I have a tough time believing that's the output from df.columns.tolist(). It looks a lot more like the output from df.columns.tolist (without the parentheses, so meaning the method itself, not the result of calling it.) Commented Jul 13, 2015 at 16:10
  • @EdChum If I reset the index, I get rid of the KeyError, but Customer1 and Customer2 are still in the dataframe. Commented Jul 13, 2015 at 16:11
  • @DSM You're right, I forgot the parenthesis Commented Jul 13, 2015 at 16:12

1 Answer 1

2

Try resetting the index:

df.reset_index()

You are then getting an autoincrementing index, but your customers index will become a column. More here: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html

After that your commands to filter the data should work.

EDIT: Use this filtering approach: df = df[~df['Company Name'].isin(['customer1', 'customer2'])]

Sign up to request clarification or add additional context in comments.

4 Comments

This helped the KeyError, but it still isn't filtering the elements.
try this filtering approach: df = df[~df['Company Name'].isin(['customer1', 'customer2'])
Yes! This worked, though it needs a closing bracket on the end. Thank you!
Great. Updated answer to reflect that :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.