Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
0
Indexable
Never
data_ipp_monthly_kem = data_ipp_monthly_kem.reset_index(drop=True)

data_ipp_monthly_kem.head()


kemerovo_okved_coal
kemerovo_okved_coal_grouped = kemerovo_okved_coal.groupby('year_month').agg({'volume_t':'sum','revenue':'sum'}).reset_index()
kemerovo_okved_coal_grouped

dataframe = data_ipp_monthly_kem.melt(id_vars=['region', 'index_name'], var_name='year_month', value_name='index_value')
dataframe['year_month'] = pd.to_datetime(dataframe['year_month'])
dataframe['year_month'] = dataframe['year_month'].apply(lambda x:x.replace(day=1))

dataframe.head(20)

merge_data_kem = pd.merge(kemerovo_okved_coal_grouped, dataframe, on='year_month', how='left')
merge_data_kem.head(20)

# Расчет процентных изменений для volume_t
merge_data_kem['volume_t_change'] = merge_data_kem.groupby('index_name')['volume_t'].pct_change() * 100 + 100

# сдвиг индекса на 1 месяц вперед
merge_data_kem['index_value'] = merge_data_kem.groupby('index_name')['index_value'].shift(-1)

# дропаем выручку

merge_data_kem['index_value'] = merge_data_kem['index_value'].astype(float)

grouped_corr = merge_data_kem.groupby('index_name').apply(lambda x: x[['volume_t', 'volume_t_change', 'index_value']].corr())
grouped_corr
Leave a Comment