Environment and Prerequisite
- Python
- Pandas
Usage
- Below samples make same result.
import pandas as pd
df = pd.DataFrame({'A': ["a", "b", "c"], 'B': [4, 5, 6]})
def modify_string(a):
return a.upper() + "1"
def add_one(a):
return a + 1
df['A'] = df['A'].apply(modify_string)
df['B'] = df['B'].apply(add_one)
df
import pandas as pd
df = pd.DataFrame({'A': ["a", "b", "c"], 'B': [4, 5, 6]})
df['A'] = df['A'].apply(lambda x: x.upper() + "1")
df['B'] = df['B'].apply(lambda x: x + 1)
df
import pandas as pd
df = pd.DataFrame({'A': ["a", "b", "c"], 'B': [4, 5, 6]})
df['A'] = df['A'].str.upper() + "1"
df['B'] += 1
df