I swear this should be easy, but I can't find the answer.
Example dataframe:
df = pd.DataFrame([['1', '3-3/4'],
['2', '1-1/2'],
['3', '2'],
['4', '5-1/4'],
['5', '6']],
columns = ["ID", "Size"])
All I want to do is to add one space before and after the value in the Size column. I've tried ljust, rjust, center, and pad, but they all fail to add because you have to account for the length of the string, which varies.
I want it to look something like this (pretend the x is a space):
I've dug around online, but cannot find a way to resolve this. Would someone point me in the right direction?
Thanks!
CodePudding user response:
IIUC, you just need
df['Size'] = ' ' df['Size'] ' '