0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

awdw

Posted at

import pandas as pd

dfmt_2 と dfmt_3 のデータフレームを読み込む想定です。

ここで具体的な読み込み方は省略しますが、通常は pd.read_csv や pd.read_excel を使います。

各分位ごとの相関係数を格納するための辞書

correlations = {}

分位 'qua1' から 'qua5' までのループ

for qua in ['qua1', 'qua2', 'qua3', 'qua4', 'qua5']:
# 分位でフィルタリング
dfmt_2_filtered = dfmt_2[dfmt_2['分位'] == qua]
dfmt_3_filtered = dfmt_3[dfmt_3['分位'] == qua]

# TDATE でマージ
merged_df = pd.merge(dfmt_2_filtered, dfmt_3_filtered, on='TDATE', suffixes=('_2', '_3'))

# Excess_Return の列で相関係数を計算
correlation = merged_df['Excess_Return_2'].corr(merged_df['Excess_Return_3'])
correlations[qua] = correlation

結果を表示

for qua, corr in correlations.items():
print(f'{qua}の相関係数: {corr}')

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?