I have a 20 x 4000 dataframe in Python using pandas. Two of these columns are named Year
and quarter
. I\'d like to create a variable called p
Although the @silvado answer is good if you change df.map(str)
to df.astype(str)
it will be faster:
import pandas as pd
df = pd.DataFrame({'Year': ['2014', '2015'], 'quarter': ['q1', 'q2']})
In [131]: %timeit df["Year"].map(str)
10000 loops, best of 3: 132 us per loop
In [132]: %timeit df["Year"].astype(str)
10000 loops, best of 3: 82.2 us per loop