我有一个用python写的项目。我想要这个程序从生产数量输入中对模糊类进行分类,基于MySQL数据库中的三个表。
表格如下:
作品
<表类>
id
年
production_quantity
interval_id
fuzzy_id
tbody><<tr>1 2016 274317 11 6 22017 200916 7 3 3 2018 217246 8 4 42019 119830 3 2 52020 66640 1 1 表类>
带注释的代码
# Merge the dataframes to add forecast_value
# column to productions dataframe
c = ['interval_id', 'forecast_value']
df = productions.merge(fuzzy_value[c], how='left')
# As the intervals are disjoint we can create a IntervalIndex
# from left and right interval columns, then use that to create a mapping series
ix = pd.IntervalIndex.from_arrays(interval_fuzzy['left_interval'],
interval_fuzzy['right_nterval'])
mapping = interval_fuzzy.set_index(ix)['interval_class']
# Use the mapping series to add interval_class based to forecast_value
df['interval_class'] = df['forecast_value'].map(mapping)
结果id year production_quantity interval_id fuzzy_id forecast_value interval_class
0 1 2016 274317 11 6 275000 A11
1 2 2017 200916 7 3 215000 A8
2 3 2018 217246 8 4 115000 A3
3 4 2019 119830 3 2 75000 A1
4 5 2020 66640 1 1 75000 A1