-1
from scholarly import scholarly
import pandas as pd
 
author_name = ["Rohan, Kelly J.","kurt ackermann"]
df = pd.DataFrame(author_name, columns=['author_name'])
df.head()
def read_author_data(author_name):
    print("Searching the name in Google scholar -- {0:s}".format(author_name))
    search_query = scholarly.search_author(author_name)
    author = scholarly.fill(next(search_query))
    if "vermont" in author["affiliation"].lower(): 
        print(author)
        try:
            home_page=author['homepage'] #all user don't have it, put it seperate
        except:
            home_page=""
            pass 
        a_data = {
            "name": author["name"],
            "affiliation": author["affiliation"],
            "area_of_interest":author['interests'],

        }
    else:
        a_data = {
            "name": "",
            "affiliation": "",
            "area_of_interest":""

        }

    return a_data
def author_details(df):
    cols = ["name",   "affiliation",  "area_of_interest"]
    df_author=pd.DataFrame(columns=cols)
    for i,rows in df.iterrows():
        try:
            a_details=read_author_data(rows[author_name])
            df_a=pd.DataFrame(a_details.items()).T
            df_a.columns = df_a.iloc[0]
            print(df_a.shape)
            df_author=df_author.concat(df_a,ignore_index=True)
        except Exception:
            #a_details={}
            pass
    return df_author   

Final line to call the function

author_details(df)

error is Getting an empty row, but there should be values for Rohan, Kelly J but there is no data for it.

The expected output is to get the details and store them in the data frame.

ouroboros1
  • 9,113
  • 3
  • 7
  • 26
  • Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Aug 17 '23 at 18:00
  • 1
    The code you provided creates an empty dataframe and does not go info `for` loop at all. So the problem can not be reproduced. – Maria K Aug 17 '23 at 18:04
  • Even further, I replaced row `df = pd.DataFrame()` with `df = pd.DataFrame({"author_name": author_name})` and the snippet still doesn't produce an error, works fine by me. – Maria K Aug 17 '23 at 18:29
  • @MariaK sorry, I missed one line of code, I hope it should work now – Rohan Vaidya Aug 17 '23 at 18:30
  • Nope, still doesn't produce an error :( does this exact snippet produce an error when you run it? – Maria K Aug 17 '23 at 18:31
  • Which line, exactly, gets that error for you? – Tim Roberts Aug 17 '23 at 18:45
  • Not getting any `error`, it works fine as i am able to get values as `list` in interests column – Sauron Aug 17 '23 at 19:13
  • @MariaK I have put code with minimum requirements to execute if I run read_author_data("Rohan, Kelly J."), I get the desired result but not in a dataframe – Rohan Vaidya Aug 17 '23 at 20:41
  • @TimRoberts, I have updated the code and am not able to store data in line author_details(df) – Rohan Vaidya Aug 17 '23 at 20:42
  • @bajju, I have updated the code and am not able to store data in line author_details(df) – Rohan Vaidya Aug 17 '23 at 20:42

1 Answers1

0

author['interests'] is a list. And you're setting it to one cell. Try:

df.at[i,"author_interest"] = ', '.join(author['interests'])
dgrigonis
  • 387
  • 5
  • 10
  • 1
    He needs to set the value as a `list` in author_interest column, You are not inserting as list and You can set value of a cell as `list`. – Sauron Aug 17 '23 at 19:14