1

I am new to Python and pandas, and I have the codes like the one that's below:

for line in TWITTER_USER_IDs:
    screen_name = line 
    start = api.GetUser(screen_name)
    friends_object = api.GetFriendIDs(start)
    followers_object = api.GetFolloerIDs(start)

    friends = json.loads(friends_object)
    followers = json.loads(followers_object)
    startj = json.laods(start)

    friends_df = pd.DataFrame(friends)
    followers_df = pd.DataFrame(followers)
    start_df = pd.DataFrame(startj)

I want to do something like:

EDGE_LIST1 = {'User':start_df,
              'Follower': friends_df }

EDGE_LIST2 = {'User': followers_df,
              'Follower': start_df }

but the number of rows of start_df and the number of rows of friends_df or followers_df are different - so I don't think I can do that.

The solution would be to repeat the entry (note: There is only one entry in start_df, as start_df only stores Twitter username of one user) in start_df number of times that is equal to friends_df or followers_df.

Can someone tell me how to do it?

I searched and searched internet but didn't get any results...

thanks

Scott Boston
  • 147,308
  • 15
  • 139
  • 187
Jin-Dominique
  • 3,043
  • 6
  • 19
  • 28
  • 1
    Try to follow [PEP 8](http://www.python.org/dev/peps/pep-0008/#naming-conventions). Your code is hard to read. – zero323 Oct 22 '13 at 23:06
  • is it better? let me know if further editing is needed – Jin-Dominique Oct 22 '13 at 23:11
  • are you looking for a join? really unclear what your question is. take out the twitter api stuff and boil down to a sample input/desired output – qwwqwwq Oct 22 '13 at 23:59
  • I think what you want to do is do an outer merge, assuming you have the username in both `start_df` and `friends_df` then you perform the merge like so df = friends_df.merge(start_df, left_on=['username'] right_on=['followee'], how='outer'). Without seeing the columns of `start_df` and `friends_df` or `followers_df` I cannot advise further, please post sample data from all dfs. – EdChum Oct 23 '13 at 07:21

0 Answers0