0

I have an index(list) called newSeries0 and I'd like to do the following.

for seriesName in newSeries0:
    seriesName=fred.get_series_first_release(seriesName)
    seriesName=pd.DataFrame(seriesName)
    seriesName=seriesName.resample('D').fillna('ffill')
    seriesName.rename(columns={'value': str(seriesName)}, inplace=True)

In other words, I'd like to create a dataframe from each name in newSeries (using this fred api) which has the (variable) name of that newSeries. Each dataframe is forward filled and the column name of the data is changed to the name of the data series.

Is zip or map involved?

In the end I'd like to have

a=dataframe of a
b=dataframe of b
c=dataframe of c

...

where a,b,c... are the names of the data series in my index(list) newSeries0, so when I call a I get the dataframe of a.

Ahmed
  • 77
  • 1
  • 9
  • 1
    What's your precise question? Does your code not work? If not, what error / result do you get versus what you expect? – jpp Aug 31 '18 at 21:52
  • The code produces only the last series. It also boggles the column name. i.e. the code erases? each df when it moves to the next one. I'd like it to save each dataframe to its name variable. – Ahmed Aug 31 '18 at 21:57
  • 1
    Are you trying to create a bunch of separate variables, with names determined by the column names of the dataframe? If so, it's probably a duplicate of [this](https://stackoverflow.com/questions/1373164/) or similar questions, but the key question is: why? What are you going to do with a bunch of variables whose names you can't actually know in advance? Why not just put them in a dict, or a DataFrame, or some other thing where you can iterate the key-value pairs or look them up by string name or otherwise actually use them? – abarnert Aug 31 '18 at 22:04

1 Answers1

0

Just use dictionary like :-

dataframe_dict = {}
for seriesName in newSeries0:
    seriesName=fred.get_series_first_release(seriesName)
    seriesName=seriesName.resample('D').fillna('ffill')
    dataframe_dict[seriesName]=seriesName

df = pd.DataFrame()
for name in dataframe_dict:
    df[name] = dataframe_dict[name]
Akash Badam
  • 476
  • 2
  • 9