Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4.  
  5. df = pd.read_csv("/Users/Dimitrios/Desktop/Stock_data/2019_12/06/HM.csv")
  6.  
  7.  
  8. #Prints the rows for all columns when the Tid column value is True with the statment
  9. #print(df.loc[df["Tid"]=="2019-12-06 17:29:53"])
  10.  
  11.  
  12.  
  13. #Makes index value based on the Tid column
  14. df2 = pd.read_csv("/Users/Dimitrios/Desktop/Stock_data/2019_12/06/HM.csv", index_col="Tid")
  15. #print(df2.at["2019-12-06 17:29:53","Volym"])
  16.  
  17.  
  18. #Makes a column thats Kurs * Volym
  19. Total_summa = df2["Kurs"]*df2["Volym"]
  20.  
  21. #Add the new column on the positioon 11 in the df. The others are pushed to the right
  22. df2.insert(11, "Total Summa", Total_summa, True)
  23.  
  24. #Makes all the index values to a list
  25. #Total_summa.index.tolist()
  26.  
  27. #Creates a dataframe from df2 with only 3 choosen columns
  28. df3 = df2.loc[:, ['Kurs', 'Volym', 'Total Summa']]
  29.  
  30.  
  31. listi = []
  32. for i in Total_summa.index.tolist():
  33. if i not in listi:
  34. listi.append(i)
  35.  
  36.  
  37. sumisum = []
  38.  
  39. print(listi[0:5])
  40. print(Total_summa.index.tolist()[0:3])
  41.  
  42. for i in listi[0:3]:
  43. print(i)
  44. b = df3.at[str(i),"Total Summa"]
  45. b = sum(b)
  46. sumisum.append(b)
  47.  
  48. print(sumisum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement