|
Python+Pandas:
import pandas as pd
import re
f = pd.ExcelFile('pandas exercise/sample344.xlsx')
lst = []
for sheet in f.sheet_names:
if sheet != '查询':
df = pd.read_excel(f, sheet, index_col=0, parse_dates=True)
lst.append(df)
df = pd.concat(lst).sort_index()
df1 = pd.read_excel(f, '查询', usecols='a:e')
for t in df1.itertuples():
l = re.split(r'-|\*', t.材质规格)
m = l[0]
s = l[1]
n = t.名称 if t.名称 != '线材' else '高线'
df2 = df[(df.品名 == n)&(df.材质 == m)&(df['规格'].str[1:] == s)&(df.index <= t.日期)]
if df2.size != 0:
df1.loc[t[0], '价格'] = df2.iloc[-1, 6]
df1 |
评分
-
1
查看全部评分
-
|