Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

concat columns pandas dataframe

In [1]: df1 = pd.DataFrame(
   ...:     {
   ...:         "A": ["A0", "A1", "A2", "A3"],
   ...:         "B": ["B0", "B1", "B2", "B3"],
   ...:         "C": ["C0", "C1", "C2", "C3"],
   ...:         "D": ["D0", "D1", "D2", "D3"],
   ...:     },
   ...:     index=[0, 1, 2, 3],
   ...: )
   
In [8]: df4 = pd.DataFrame(
   ...:     {
   ...:         "B": ["B2", "B3", "B6", "B7"],
   ...:         "D": ["D2", "D3", "D6", "D7"],
   ...:         "F": ["F2", "F3", "F6", "F7"],
   ...:     },
   ...:     index=[2, 3, 6, 7],
   ...: )
   ...: 

In [9]: result = pd.concat([df1, df4], axis=1)
# This will merge columns of both the dataframes
Comment

how to concat on the basis of particular columns in pandas

In [6]: result = pd.concat(frames, keys=['x', 'y', 'z'])
Comment

PREVIOUS NEXT
Code Example
Python :: python panda append rows to csv python 
Python :: python3 shebang 
Python :: scipy cosine similarity 
Python :: django migrate model 
Python :: python file hashlib 
Python :: underscore in python 
Python :: Get Time from timestamp in python 
Python :: how to make a nan value in a list 
Python :: import get user model django 
Python :: end python print with space 
Python :: python optional arguments 
Python :: msg.author discord.py 
Python :: tkinter filedialog get directory path 
Python :: discord.py edit messages 
Python :: tkinter button 
Python :: .launch.py file in ros2 
Python :: python fstring 
Python :: Game of Piles Version 2 codechef solution 
Python :: python loop back to start 
Python :: fillna with median , mode and mean 
Python :: remove space characters from string in python 
Python :: how to play and stop music python 
Python :: word embedding python 
Python :: python string format 
Python :: extract nonzero array elements python 
Python :: pandas apply lambda function with assign 
Python :: Exception Value: Object of type User is not JSON serializable 
Python :: np.select with multiple conditions 
Python :: python get current class name 
Python :: save turtle programming python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =