Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python merge strings in columns

df["period"] = df["Year"].astype(str) + df["quarter"]
Comment

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

PREVIOUS NEXT
Code Example
Python :: Program to find GCD or HCF of two numbers python 
Python :: flask print request headers 
Python :: python join dict 
Python :: python input float 
Python :: remove prefix from string python 
Python :: render django template 
Python :: change a cell in pandas dataframe 
Python :: sort in python 
Python :: python using random module 
Python :: select multiple dict 
Python :: next iteration python 
Python :: all select first value in column list pandas 
Python :: Get current cursor type and color Tkinter Python 
Python :: how to print specific part of a dictionary in python 
Python :: python makedir 
Python :: local ip 
Python :: undefined in python 
Python :: what is cross entropy loss in pytorch example 
Python :: boids algorithm 
Python :: pyodbc cursor create list of dictionaries 
Python :: check if list elememnt in dataframe column 
Python :: paradigm meaning in python 
Python :: python create dummy dataframe 
Python :: how to calculate the variance of all columns in python 
Python :: python create temp file 
Python :: check auth user django 
Python :: python index max list 
Python :: tiff to jpg in python 
Python :: python image crop 
Python :: install python 3.8 on wsl 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =