0

How to add multiple columns from one dataframe to another dataframe i laready figured out to add a single column but not getting multiple columns. I am a newbie

df

new['Symbol']= pd.Series(df['Symbol'])
dfnew['Symbol']['Desc']= pd.Series(df['Symbol']['Desc'])
1
  • dfnew['Symbol']= pd.Series(df['Symbol']) # worked dfnew['Symbol']['Desc']= pd.Series(df['Symbol']['Desc']) # not working Commented Jun 14, 2019 at 8:13

1 Answer 1

1

Use:

dfnew['Symbol'],dfnew['Desc']= df['Symbol'],df['Desc']

Or df.assign():

dfnew=dfnew.assign(Symbol=df.Symbol,Desc=df.Desc)

If needed initialize dfnew first as dfnew=pd.DataFrame()

Sign up to request clarification or add additional context in comments.

4 Comments

dfnew=dfnew.assign(Symbol=df.Symbol,Desc=df.Desc this worked for me thank you so much.
can you help with creating a file if exists add with number for Ex:SMA_Outliers.csv SMA_Outliers(1).csv ......
@Hareesha that is a separate question which will require separate libraries, not pandas. :) I suggest you post a fresh question.
@Hareesha may be you can check: stackoverflow.com/questions/17984809/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.