-1
$\begingroup$

I have a dataframe (csv file) which consists of about 8000 songs (column name "Song")of e.g. 20 singers(column name "Artist"), so each singer has more than one song. I want to select rows from this dataset that will contain one song of a singer, for example first songs of each singer. So my new pd.dataset will contain 20 songs which singers are different. Please, can anyone help me?

$\endgroup$
2
$\begingroup$

Well assuming df is your Pandas dataframe you could sort it by Artist and then do something like this:

df = df.drop_duplicates(subset='Artist', keep='first')

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.