Issue
I have a dataframe and I want to change the characters under the column Model
. I want to use the codes solely and not the definition of the codes.
import pandas as pd
data = {
'Model': ['Audi', 'Mercedes', 'Volkswagen'],
'Code': ['["CFA4 - replace filters"]', '["C09 - reboot the engine"]', '["O06 - clean the exhaust pipe"]']
}
df = pd.DataFrame(data)
Desired output
Model Code
Audi CFA4
Mercedes C09
Volkswagen O06
Solution
Using only string functions, you can try:
df["Code"] = df["Code"].str[2:-2].str.split(" - ").str[0]
>>> df
Model Code
0 Audi CFA4
1 Mercedes C09
2 Volkswagen O06
Answered By - not_speshal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.