0

I have several data frames and for all of them, I want to carry out the same procedure. As an example, for one data frame (df1), the code looks the following:

def create_url():
    df_id = (str(str((df1['id'].tolist()))[1:-1])).replace(" ", "")
    ids1 = "ids=" + df_id1
    url1 = "https://api.twitter.com/2/tweets?{}&{}".format(ids1, tweet_fields)
    return url1

However, for all df which I have I want to loop this code in order to get one url per df (which are names then url1, url2, etc.). To get the whole list of names of df, I used the following code:

for j in dfs:
    print(j)

Hope somebody can help!

Thank you a lot in advance!

zr0gravity7
  • 2,917
  • 1
  • 12
  • 33
  • for formatting your list of ids, look at str.join instead of this odd slicing and replacing bit. – njzk2 Aug 19 '21 at 19:54

1 Answers1

0

If i understand correctly
Try this:

def create_url(dfx):
    df_id = (str(str((dfx['id'].tolist()))[1:-1])).replace(" ", "")
    ids = "ids=" + df_id
    url = "https://api.twitter.com/2/tweets?{}&{}".format(ids, tweet_fields)
    return url


for j in dfs:
    print(j)
    create_url(j)
dimelu
  • 68
  • 3