pandas string extract

mail@pastecode.io avatar
unknown
python
a year ago
628 B
15
Indexable
Never
# importing pandas as pd
import pandas as pd

# importing re for regular expressions
import re

# Getting All Column and Rows Data
df = pd.read_csv("datafolder/data.csv")
# printing All Column and Rows Data
print(df)

# Getting the "Line" Column
df2 = df["Line"]
# printing the "line" Column data
print(df2)

# Getting the "Index" Column
idx = df["Index"]

# printing the "Index" Column
# print(df)

# Creating the Df Index from the "Index" Column
df.index = idx

# extract groups having with the string "BEROWNE."
result = df["Line"].str.extract(pat="(BEROWNE\.)")

# print the result
print(result)