Facebook
From Walloping Pheasant, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 73
  1. import pandas as panda
  2. import numpy as np
  3.  
  4. def PANDAS_DONE():
  5.     read = panda.read_csv('statek.txt', sep='\t')
  6.     select = panda.DataFrame(read)
  7.     # print(select)
  8.     # print(read)
  9.  
  10.     select['data'] = panda.to_datetime(select['data'])
  11.  
  12.     funds = 500000
  13.     print("Fundusze", funds)
  14.  
  15.     czas = (select['data'] <= '2018-12-18')
  16.     Z = (select['Z/W'] == 'Z')
  17.     W = (select['Z/W'] == 'W')
  18.  
  19.     # ------------------------------------------------------------------------
  20.     #kolumna stan_finansów to .......
  21.  
  22.     wyd = select['wydatki'] = select['ile ton'] * select['cena za tone w talarach']
  23.     #print(select)
  24.     #print(select['wydatki'].cumsum())
  25.  
  26.     # Generujemy listę wykorzystując Python Pandas oraz jej zawartość zapisujemy do kolumny 'Result'
  27.     result = []
  28.     y = select['wydatki'][0]
  29.  
  30.     if select['Z/W'][0] == 'Z':
  31.         x = funds - y
  32.         print(x)
  33.         result.insert(0, x)
  34.     elif select['Z/W'][0] == 'W':
  35.         x = funds + y
  36.         print(x)
  37.         result.insert(0,x)
  38.  
  39.     #for val in select['wydatki'][1:]:
  40.     for i in range(1,len(select['wydatki'])):
  41.         val = select['wydatki'][i]
  42.         if select['Z/W'][i] == 'Z':
  43.             result.append(x - val)
  44.         else:
  45.             result.append(x + val)
  46.  
  47.     select["result"] = result
  48.     #print(select)
  49.  
  50.     #sel = select.loc[(select['data'] == '2018-10-08')]
  51.     #print(sel)
  52.     print(select.groupby('data').max('result').sort_values(by='result', ascending=False))
  53.  
  54.  
  55. def main():
  56.     PANDAS_DONE()
  57.  
  58.  
  59. if __name__ == '__main__':
  60.     main()