I'm trying to add a prefix to a DataFrame in pandas. It supposes to be very easy:
import pandas as pd
a=pd.DataFrame({
'x':[1,2,3],
})
#this one works;
"mm"+a['x'].astype(str)
0 mm1
1 mm2
2 mm3
Name: x, dtype: object
But surprisingly, if I want to use a prefix of single letter 'm', it stops working:
#this one doesn't work
"m"+a['x'].astype(str)
TypeError Traceback (most recent call last)
<ipython-input-21-808db8051ebc> in <module>
1 #this one doesn't work
----> 2 "m"+a['x'].astype(str)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\ops\__init__.py in wrapper(left, right)
1014 if is_scalar(right):
1015 # broadcast and wrap in a TimedeltaIndex
-> 1016 assert np.isnat(right)
1017 right = np.broadcast_to(right, left.shape)
1018 right = pd.TimedeltaIndex(right)
TypeError: ufunc 'isnat' is only defined for datetime and timedelta.
So my questions are:
How to solve the problem?
What happened, it seems pandas is trying to do something fancy?
Why is 'm' is so special? (it seems other single letters are ok, e.g. 'b').