201.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import cudf
  2. import multiprocessing as mp
  3. from sqlalchemy import create_engine
  4. from datetime import datetime as dt
  5. import pandas as pd
  6. import logging
  7. def t(df, u):
  8. st = dt.now()
  9. t = cudf.DataFrame()
  10. try:
  11. for i in range(len(df)):
  12. t = cudf.concat([t, df.iloc[i].to_frame().T], axis=0)
  13. except BaseException as e:
  14. print(e)
  15. t.loc[i + 1, 'HL'] = 1
  16. print(f'{u}完成,{dt.now() - st}')
  17. if __name__ == '__main__':
  18. # mp.freeze_support()
  19. logger = mp.log_to_stderr()
  20. logger.setLevel(logging.DEBUG)
  21. engine = create_engine(
  22. 'mysql+pymysql://root:r6kEwqWU9!v3@172.18.0.4:3306/qmt_stocks_whole?charset=utf8')
  23. # engine = create_engine(
  24. # 'mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qmt_stocks_whole?charset=utf8')
  25. df = pd.read_sql_table('000001.SZ_1d', con=engine.connect())
  26. df = cudf.from_pandas(df)
  27. print(df.shape)
  28. # df_cudf = cudf.from_pandas(df)
  29. pool = mp.Pool(2)
  30. try:
  31. for j in range(1):
  32. pool.apply_async(func=t, args=(df, j))
  33. pool.close()
  34. pool.join()
  35. except BaseException as e:
  36. print(e)