中兴捧月-迪杰特斯拉
程序员文章站
2022-05-22 10:54:19
...
import numpy as np
import pandas as pd
PATH='./train_step2.csv'
TEST='./test_step2.csv'
RELT = 'result_step2.txt'
# 训练数据读取
df = pd.read_csv(PATH)
# 待测试数据读取
ts = pd.read_csv(TEST)
# 整理数据
df1 = df.pivot(index='id', columns='date', values='value')
# 现将待填写数据填补一列
ts['value']='nan'
# 将需要填写的id及其前标签提取出来
index_ts = ts[~ts.duplicated('id')]['id']
m = 0
toData = []
for i in range(index_ts.index.size):
# 提取目的id
target = index_ts.iloc[i]
# 拿出最后五个数据的describe
des = df1.loc[target].tail(5).describe()
# 为了避免干扰值,最高和最低都不用
tailValue = (des['50%'] + des['75%'])/2
# 如果所得值为nan则赋值为nan
if(~np.isnan(tailValue)):
toVal = tailValue
else:
toVal = 'nan'
# 将值填入
for j in range(91):
toData.append(toVal)
# 将值填入
ts['value'] = toData
ts.to_csv(RELT, index=False)
#这版分最高排38,就用这版,最后还被刷了(报告才是重点)...
上一篇: 1179:奖学金
下一篇: Codeforces510B【dfs】