# Write a Python program to separate a series of alphabets and digits and convert them to a dataframe

PythonPandasServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Assume you have a series and the result for separating alphabets and digits and store it in dataframe as,

series is:
0    abx123
1    bcd25
2    cxy30
dtype: object
Dataframe is
0   1
0 abx 123
1 bcd 25
2 cxy 30

To solve this, we will follow the below approach,

## Solution

• Define a series.

• Apple series extract method inside use regular expression pattern to separate alphabets and digits then store it in a dataframe −

series.str.extract(r'(\w+[a-z])(\d+)')

### Example

Let’s see the below implementation to get a better understanding −

import pandas as pd
series = pd.Series(['abx123', 'bcd25', 'cxy30'])
print("series is:",series)
df = series.str.extract(r'(\w+[a-z])(\d+)')
print("Dataframe is:" ,df)

### Output

series is:
0    abx123
1    bcd25
2    cxy30
dtype: object
Dataframe is
:  0   1
0 abx 123
1 bcd 25
2 cxy 30
Updated on 24-Feb-2021 10:06:48