Reputation:
In 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
Reputation: 21
Not a pandas expert but this might help:
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