How do I split last 3 digits in values in a column in a Dataframe into two new Dataframes?

bdoe85 :
df=pd.DataFrame({'col1':[25021,25002,8002,40211,2232,""]})

    col1    
0   25021    
1   25002
2   8002
3   40211
4   2232
5   

I would like to get the following, not too sure how to split based on last 3 digits into col3 and whatever preceding into col1

    col2   col3    
0   25     021       
1   25     002       
2   8      002      
3   40     211       
4   2      232 
5
Quang Hoang :

This is my approach:

df['col2'] = df['col1'].astype(str).str[-3:]

df['col1'] = df['col1'].astype(str).str[:-3]

Output:

   col1 col2
0    25  021
1    25  002
2     8  002
3    40  211
4     2  232

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=408265&siteId=1
Recommended