Iterating through a list and storing results
Question:
I have a very simple script that looks as such:
from instagramy import InstagramUser
user = InstagramUser("shanutxo")
If you run this, it should return a response that looks as follows:
⚡️S H A N U T A N A U T⚡️ (shanutxo) -> life, style,
empowerment + entrepreneurship via real estate + more.➕
But the way I need it to work, the script is iterating through multiple usernames that would plug into InstagramUser("")
. It would then capture the output, store in a dataframe, and move on to the next name in the list. I have attempted to try something like:
import pandas as pd
from instagramy import InstagramUser
users = [['hannahkshepherd'],['sydneyhopeee'],['shanutxo'],['sunshinejilll']]
users_df = pd.DataFrame(users, columns=['usernames'])
ser = users_df.apply(InstagramUsers, axis=1, raw=True)
pd.concat([users_df, pd.DataFrame(ser, columns="bio")], axis=1)
But it gives me the error: NameError: name 'InstagramUsers' is not defined
From Alexander’s answer, I try:
import pandas as pd
from instagramy import InstagramUser
users = ['calvinharris','beyonce','adele']
users_df = pd.DataFrame(users, columns=['username'])
print(users_df)
ser = users_df['username'].apply(InstagramUser)
print(ser)
test = pd.concat([users_df, pd.DataFrame(ser,columns=["bio"])], axis=1)
This returns a response that looks like:
But it’s not capturing the response text (For example, the response for beyonce should be stored as something like "CUFF IT ㅤ season")
Answers:
Using your previous example… you could try something like this.
This worked for me
users = ['calvinharris','beyonce','adele']
users_df = pd.DataFrame(users, columns=['username'])
print(users_df)
ser = users_df['username'].apply(InstagramUser)
print(ser)
pd.concat([users_df, pd.DataFrame(ser,columns=["bio"])], axis=1))
This is the output I get from the print(ser)
statement
0 Calvin Harris (calvinharris) -> Funk Wav Bounc...
1 Beyoncé (beyonce) -> CUFF IT ㅤ season
2 Adele (adele) ->
I have a very simple script that looks as such:
from instagramy import InstagramUser
user = InstagramUser("shanutxo")
If you run this, it should return a response that looks as follows:
⚡️S H A N U T A N A U T⚡️ (shanutxo) -> life, style,
empowerment + entrepreneurship via real estate + more.➕
But the way I need it to work, the script is iterating through multiple usernames that would plug into InstagramUser("")
. It would then capture the output, store in a dataframe, and move on to the next name in the list. I have attempted to try something like:
import pandas as pd
from instagramy import InstagramUser
users = [['hannahkshepherd'],['sydneyhopeee'],['shanutxo'],['sunshinejilll']]
users_df = pd.DataFrame(users, columns=['usernames'])
ser = users_df.apply(InstagramUsers, axis=1, raw=True)
pd.concat([users_df, pd.DataFrame(ser, columns="bio")], axis=1)
But it gives me the error: NameError: name 'InstagramUsers' is not defined
From Alexander’s answer, I try:
import pandas as pd
from instagramy import InstagramUser
users = ['calvinharris','beyonce','adele']
users_df = pd.DataFrame(users, columns=['username'])
print(users_df)
ser = users_df['username'].apply(InstagramUser)
print(ser)
test = pd.concat([users_df, pd.DataFrame(ser,columns=["bio"])], axis=1)
This returns a response that looks like:
But it’s not capturing the response text (For example, the response for beyonce should be stored as something like "CUFF IT ㅤ season")
Using your previous example… you could try something like this.
This worked for me
users = ['calvinharris','beyonce','adele']
users_df = pd.DataFrame(users, columns=['username'])
print(users_df)
ser = users_df['username'].apply(InstagramUser)
print(ser)
pd.concat([users_df, pd.DataFrame(ser,columns=["bio"])], axis=1))
This is the output I get from the print(ser)
statement
0 Calvin Harris (calvinharris) -> Funk Wav Bounc...
1 Beyoncé (beyonce) -> CUFF IT ㅤ season
2 Adele (adele) ->