-3

i have a data frame with 41 columns (and n rows). i want to add another data frame to main data frame (as new columns). the new data frame that should add to the main can have different numbers of column but have same number of rows with main data frame.for example:

enter image description here

new data frame should be:

enter image description here

is there any function to do it?

Hadi Taj
  • 71
  • 9
  • Does this answer your question? [Adding new column to existing DataFrame in Python pandas](https://stackoverflow.com/questions/12555323/adding-new-column-to-existing-dataframe-in-python-pandas) – David Jul 14 '20 at 17:19
  • 1
    ``pd.concat([df1,df2], axis=1) `` – sushanth Jul 14 '20 at 17:20
  • `pd.concat([df1, df2], axis=1, sort=False)` – bigbounty Jul 14 '20 at 17:21
  • 1
    Does this answer your question? [Concatenate rows of two dataframes in pandas](https://stackoverflow.com/questions/28135436/concatenate-rows-of-two-dataframes-in-pandas) – MrNobody33 Jul 14 '20 at 17:23

2 Answers2

0

It looks like you tagged pandas (pd), so assuming you are using that, you can use:

pd.merge('main data frame', 'second data frame', left_index=True)
rmoore35
  • 65
  • 3
  • 9
0

You can use pd.concat:

new_df = pd.concat([main_df,second_df], axis=1)  
Caldass_
  • 82
  • 6