Reputation: 6940
Here is my code:
import pandas as pd
import numpy as np
data = {'ID': [1,2,3,4,5,6,7,8,9],
'Doc':['Order','Order','Inv','Order','Order','Shp','Order', 'Order','Inv'],
'Rep':[101,101,101,102,102,102,103,103,103]}
df = pd.DataFrame(data)
#df['concat']= (df['ID'].convert_dtypes(convert_string = True) + "1").convert_dtypes(convert_integer = True)
df['concat']= (df['ID'].astype(str) + "1").convert_dtypes(convert_integer = True)
print(df['concat'].dtype)
output:
string
Why df['concat']
is not Int64
and how to get it?
Upvotes: 0
Views: 437
Reputation: 10970
Try
>>> df['concat'] = df['ID'].astype(str).add('1').astype('int64')
0 11
1 21
2 31
3 41
4 51
5 61
6 71
7 81
8 91
Name: ID, dtype: int64
Upvotes: 2