user19589852
user19589852

Reputation:

In my output I want unique customer ID with customer name

enter image description hereenter image description hereIn my output I want unique customer ID with customer name. Is that possible? (both 'Customer ID' and 'Customer Name' in my data frame) In output I am getting only the 'Customer ID' but I want Customer name as well.

[df3['Customer ID'].unique()]['Customer Name']

Upvotes: 0

Views: 658

Answers (1)

Ben Ruland
Ben Ruland

Reputation: 21

Not a pandas expert but this might help:

  1. Im interpreting your question as asking for a table containing customer IDs and their associated customer Name. Where no two customer ID's are duplicated.

First you can winnow down the table with this line

df = df.drop_duplicates(subset = ["Customer ID"])

At this point df will contain the first occurence of each unique customer ID and all the associated information in the other columns of these rows.

Then you can grab just the first two columns Customer ID and Customer Name by slicing. This looks like

df.loc[:["Customer ID","Customer Name"]]

As I said Im no pandas expert, there are likely better ways but this should get the job done.

As a note you may want to make copies of your dataframe and do these operations on the copies so as to not loose your original data if you wish to do further operations.

Upvotes: 1

Related Questions