I have a lot of pandas timeseries that I would like to combine into a dataframe. The dataframe that results from it does not have column names. Is there some way to reuse the name of the timeseries (s_a, s_b, s_c,... ) in the dataframe without having to explicitly specify it?
import pandas as pd
import numpy as np
dates = pd.date_range('2017-01-01', '2017-03-01')
s_a = pd.Series(np.random.randn(60), index = dates)
s_b = pd.Series(np.random.randn(60), index = dates)
s_c = pd.Series(np.random.randn(60), index = dates)
s_d = pd.Series(np.random.randn(60), index = dates)
df_a = pd.concat([s_a, s_b, s_c, s_d], join='outer', axis = 1)
I am hoping something along the lines
s_list = [s_a, s_b, s_c, s_d]
and then a hypothetical function s_list.names applied after the construction of the dataframe.
df_a = pd.concat(s_list, join='outer', axis = 1)
df_a.columns = s_list.names()
will produce the desired dataframe.