1
複数のデータフレームに同じ名前の列があります。これらのデータフレームは辞書に格納されます。今私は辞書にあるそれらのデータフレームに同じ名前(およびそれぞれの日付)の列を追加し、その結果を新しいデータフレームに保存したいと考えています。Python辞書に格納されている異なるデータフレーム(一致する日付)の列を追加する
私が持っているコードは、これまでのところ...非常に遠く、このような問題に取り組む方法について
#create a new empty dataframe
sum_df = pd.DataFrame()
# my dataframes are stored in the dictionary frames_dict
for tables in frames_dict:
df = frames_dict[tables]
df = df[(df['date'] >= '01.01.2010') & (df['date'] <'01.01.2011')]
#here I filter for all columns starting with "a4_"
filter_col = [col for col in list(df) if col.startswith('a4_')]
df2 = df[["date","filter_col"]
sum_df = sum_df + df2
任意の提案を私を得るdoest?
ありがとうございました!私はあなたのコードを実装しようとしましたが、次のようなエラーが表示されます: "df = pd.DataFrame({tables:frames_dict [tables]})" - > ValueError:すべてのスカラー値を使用する場合は、 。どのインデックスを使用する必要がありますか? – AaronDT
'frames_dict'のサンプルを渡していただけますか? – ragesz
データム\t a1_1000 \t a4_1045 \t a5_1464 2009-01-01 \t 340.780 \tナン\tナン 2009-01-02 \t 493.660 \tナン\tナン 2009-01-03 \t 3754.860 \tナン\tナン 2009年1月4日\t 7580.570 \tナン\tナン 2009-01-05 \t 9582.770 \tナン\tナン 2009-01-06 \t 7525.220 \t 5370.350 \tナン – AaronDT