bpr
bpr

Reputation: 477

How to add Series as a column in a DataFrame (Pandas)?

I have a Dataframe that comes out fine from an API pull but when I try to add columns to this Dataframe all of the entries come out as NaN. I know there must be an issue when I actually try and add the Series to the Dataframe because I returned the Series individually and they came out fine. This is the code I'm using:

account = pd.Series([Acct.name]*len(frame.index))
frame['Account'] = account
date = pd.Series([st]*len(frame.index))
frame['Date'] = date

Upvotes: 1

Views: 3455

Answers (1)

bpr
bpr

Reputation: 477

Acct.name and st are just values I want added to the columns, changed my code to:

frame['Account'] = pd.Series([Acct.name]*len(frame.index))
frame['Date'] = pd.Series([st]*len(frame.index))

and it worked..

Upvotes: 1

Related Questions