Data Mining in Python for Excel MID Function

data_mining
excel
python

#1

Hey All,
I have a category column with fixed length and i want to create a new column which contain middle 3 character.

For example:
Input column: AB345NJG,ABZ26HJB
Output: “345”,“Z26”

Do we have any python function(Like MID Function in Excel) ?

Thank You.


#2

Hi @rock_bt,

You can use the following code to get those three digits:

df['Output_column'] = df['Input_Column'].astype(str).str[2:5] 

Here,
df is the name of your dataframe
Input_Column is the name of your input column which contains AB345NJG,ABZ26HJB, etc.
Output_Column will be the new column in your data frame which will contain the three letters like 345, Z26, etc.

Hope this helps!


#3

Thank You @ Pulkit