Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas add two string columns

# if both columns are strings, you can concatenate them directly
df["period"] = df["Year"] + df["quarter"]

# If one (or both) of the columns are not string typed, you should convert it 
# (them) first,
df["period"] = df["Year"].astype(str) + df["quarter"]
Comment

pandas dataframe add two columns int and string

df = df['Day'].map(str) + '-' + df['Month'].map(str) + '-' + df['Year'].map(str)
Comment

pandas dataframe add two columns int and string

df1 = df['1st Column Name'].map(str) + df['2nd Column Name'].map(str) + ...
Comment

add values from 2 columns to one pandas

df['Fruit Total']= df.iloc[:, -4:-1].sum(axis=1)
print (df)
   Apples  Bananas  Grapes  Kiwis  Fruit Total
0     2.0      3.0     NaN    1.0          5.0
1     1.0      3.0     7.0    NaN         11.0
2     NaN      NaN     2.0    3.0          2.0
Comment

PREVIOUS NEXT
Code Example
Python :: code for merge sort 
Python :: pyhton image resize 
Python :: map function in python 
Python :: pytest - parameterizing tests 
Python :: python .findall 
Python :: random choice sampling numpy 
Python :: register template tag django 
Python :: slicing in python 
Python :: how to define functions in python 
Python :: python filter() 
Python :: randomly pick a value in the list 
Python :: python processpoolexecutor 
Python :: power of array 
Python :: how to load user from jwt token request django 
Python :: open file dialog on button click pyqt5 
Python :: pandas create sample dataframe 
Python :: python function docstring 
Python :: django bootstrap 
Python :: how to use %s python 
Python :: flask structure 
Python :: Python random integer number between min, max 
Python :: python sort algorithm 
Python :: sklearn train test split 
Python :: check runtime python 
Python :: check multiple keys in python dict 
Python :: atan2 of number python 
Python :: how to use assert in python 
Python :: Link In Django 
Python :: python delete key dictionary 
Python :: group by list python 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =