-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_process.py
56 lines (42 loc) · 1.27 KB
/
data_process.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import pandas as pd
from datetime import datetime
excel_file = 'input.xlsx'
res = 'output.xlsx'
def get_data():
df = pd.read_excel(excel_file)
print(df.columns)
print(df)
def update_date():
df = pd.read_excel(excel_file)
df['测量日期'] = df['测量日期'].apply(lambda x: datetime.strptime(x, '%Y/%m/%d').replace(year=2023).strftime('%Y/%m/%d'))
# print(df)
df.to_excel(res, index=False)
def random_data():
df = pd.read_excel(res)
columns = list(df.columns)[2:]
df[columns] = df[columns].apply(pd.to_numeric, errors='coerce')
# print(columns)
k = np.random.uniform(0.8, 1.4)
df[columns] *= k
# print(df[0:10])
df.to_excel(res, index=False)
def after_rain_9():
"""
update month 9
"""
df = pd.read_excel(res)
mask = df['测量日期'] == '2023/10/04'
selected_rows = df[mask]
columns_to_adjust = list(df.columns)[2:]
k = np.random.uniform(1, 1.4)
selected_rows[columns_to_adjust] *= k
df[mask] = selected_rows
# print(df[mask])
df.to_excel(res, index=False)
if __name__ == "__main__":
# get_data()
# update_date()
# random_data()
after_rain_9()
# get_data()