ferrelwill
ferrelwill

Reputation: 821

append series in a for loop python

How can I append the pd.series output in a loop

Input

for hours in fun(data, 24*10):
    model.fit(hours)
    df['output'] = pd.Series(model.predict(hours))

I want something like this

lst=[]

for hours in fun(data, 24*10):
    model.fit(hours)
    x = pd.Series(model.predict(hours))
    lst.append(x)

df['output'] = pd.DataFrame(lst)

Upvotes: 0

Views: 508

Answers (1)

above_c_level
above_c_level

Reputation: 3929

pd.concat should work:

lst=[]

for hours in fun(data, 24*10):
    model.fit(hours)
    x = pd.Series(model.predict(hours))
    lst.append(x)

df['output'] = pd.concat(lst, axis=0)

Upvotes: 1

Related Questions