Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_stations.py 1007 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. # Created by: leo
  2. # Created on: 2018.12.14
  3. import pytest
  4. import pandas as pd
  5. from coef_matrix import classify
  6. @pytest.fixture
  7. def load_data():
  8. raw = pd.read_csv('../HuBeiShaYang/hbpv10days.csv',
  9. usecols=[0, 1, 2, 3, 4, 6],
  10. names=['time', 'station', 'lev1', 'lev2', 'strno', 'current'],
  11. dtype={'lev1':str, 'lev2':str, 'strno':str},
  12. parse_dates = ['time']).dropna()
  13. inp = raw[(raw['current'] >= 0) & (raw['current'] < 10)]
  14. pd.options.mode.chained_assignment = None
  15. inp['day'] = inp['time'].map(lambda x: x.date())
  16. # 没有 set_index 会导致 grps.apply() 出现日期不在 Index 中错误
  17. inp2 = inp.set_index(['station', 'lev1', 'lev2', 'day'])
  18. grps = inp2.groupby(inp2.index)
  19. return grps
  20. def test_classify(load_data):
  21. df1 = load_data.apply(classify)
  22. df2 = df1.reset_index()
  23. res = df2.rename(columns={'level_0': 'cid'})
  24. res.to_csv('res_one_process.csv', index=False)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...