Create datasets based on authors from another dataset

Question:

I have a dataset in the following format


       text          author        title 
     -------------------------------------

dt =   text0         author0       title0
       text1         author1       title1
         .             .              .
         .             .              .
         .             .              .  

and I would like to create different separate datasets which contain only texts of one author. For example the dataset names dt1 contains the texts of the author1, the dt2 contains texts of the author2, etc.

I would be grateful if you could help me with this using python.

Update:

dt = 
            text                                     author        title
-------------------------------------------------------------------------
0   I would like to go to the beach                   George       Beach
1   I was in park few days ago                        Nick         Park
2   I would like to go in uni                         Peter        University
3   I have be in the airport at 8                     Maria        Airport
                                                    
Asked By: John Angelopoulos

||

Answers:

Please try, this is what I understand you require.

import pandas as pd

data = {
    'text' : ['text0', 'text1', 'text2'],
    'author': ['author0', 'author1', 'author1'],
    'title': ['Comunicación', 'Administración', 'Ventas']
}

df = pd.DataFrame(data)
df1 = df[df["author"]=="author0"]

df2 = df[df["author"]=="author1"]
print(df1)
print(df2)

Update:

import pandas as pd

data = {
    'text' : ['text0', 'text1', 'text2'],
    'author': ['author0', 'author1', 'author1'],
    'title': ['Comunicación', 'Administración', 'Ventas']
}

df = pd.DataFrame(data)
df1 = df[df["author"]=="author0"]

df2 = df[df["author"]=="author1"]

list_author = df['author'].unique().tolist()

for x in list_author:
  a = df[df["author"]==x]
  print(a)
Answered By: Alejandra Rojas
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.