Advertisement
ToinasMaker

pandas

Nov 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. filename = "C:/code/IntelligentSuit/tweet.csv"
  2. df_in = pd.DataFrame()
  3.  
  4.  
  5. def printdiffs(df_in):
  6. df_out = find_diffs(df_in)
  7. return df_out
  8.  
  9. def find_diffs(df_in):
  10. diff_df = pd.DataFrame()
  11. df_latest = pd.read_csv(filename)
  12. diff_df = pd.merge(df_latest, df_in, how='outer', indicator='Exist')
  13. diff_df = diff_df.loc[diff_df['Exist'] != 'both']
  14. return diff_df
  15.  
  16. def find_populartweet(dif_ls):
  17. spy = 0
  18. kaboom = 0
  19. dropin = 0
  20. sneaky = 0
  21.  
  22. if (dif_ls.shape[0] > 0):
  23. dif = dif_ls
  24. dif.columns =['number','tweet','exists']
  25. kaboom = dif.tweet.str.count("#IMEC18 kaboom").sum()
  26. print "kaboom: " + str(kaboom)
  27. dropin = dif.tweet.str.count("#IMEC18 drop").sum()
  28. print "dropin: " + str(dropin)
  29. sneaky = dif.tweet.str.count("#IMEC18 sneaky").sum()
  30. print "sneaky: " + str(sneaky)
  31.  
  32. if (kaboom > dropin and kaboom > sneaky):
  33. print "kaboom wins"
  34. if (dropin > sneaky and dropin > kaboom):
  35. print "dropin wins"
  36. if (sneaky > kaboom and sneaky > dropin):
  37. print "sneaky wins"
  38.  
  39.  
  40.  
  41.  
  42.  
  43. if __name__== '__main__':
  44. df_last = pd.DataFrame()
  45. df_in = pd.read_csv(filename)
  46. print "first df in " + str(df_in.shape[0])
  47. i=0
  48.  
  49. while True:
  50. print("Polling Tweets")
  51. dif_ls= printdiffs(df_in)
  52. # print "dataframe rows " + str(dif_ls.shape[0])
  53. # print "dataframe cols" + str(len(dif_ls.columns))
  54. print str(dif_ls.columns[2])
  55. if (dif_ls.shape[0] > 0):
  56. find_populartweet(diff_df)
  57. print str((dif_ls._slice(slice(0, None))))
  58. if ('#IMEC18 spy' in str(dif_ls._slice(slice(0, None)))):
  59. print ("show spy")
  60. if ('#IMEC18 kaboom' in str((dif_ls._slice(slice(0, None))))):
  61. print("show kaboom")
  62. if ('#IMEC18 drop' in str((dif_ls._slice(slice(0, None))))):
  63. print("show drop-in")
  64. if ('#IMEC18 sneaky' in str((dif_ls._slice(slice(0, None))))):
  65. print("show sneaky")
  66. df_in = pd.read_csv(filename)
  67. print "waiting 10 seconds"
  68. time.sleep(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement