3个表之间输入的分类值



我有一个用python写的项目。我想要这个程序从生产数量输入中对模糊类进行分类,基于MySQL数据库中的三个表。

表格如下:

作品

<表类> id 年 production_quantity interval_id fuzzy_id tbody><<tr>12016274317116220172009167332018217246844201911983032520206664011

带注释的代码

# 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

最新更新