After a whole day of trying to solve a part of additional exercise I give up.
The task is: “See if there are particular keywords in the name column that you can extract as new columns”. I found that the ‘name’ column has brand name in the string ( same as ‘brand’ column). ex:
I was trying to drop this name from a string ( column “name”: starts with this name/brand). The problem is: not all rows have a brand name, so I can’t use autos[‘name’].str[1:].str.join(sep=" "). for ex (row 7):
My code:
# See if there are particular keywords in the name column that you can extract as new columns:
#The only reasonable split we can find is the **"name"** column. In a matter of fact, it won't be split, #because the name of the brand exists now. Because the **"name"** column has it too, we will drop it.
autos['name'] = autos['name'].str.replace("_", ' ').astype(str)
autos['name'] = autos['name'].str.split() # split string to list
brand_maybe = autos['name'].str[0].str.lower() # looking for brands; lowercase conversion
test_name = autos['brand'] == brand_maybe # boolean comparison
print(test_name) # test
I tried to use boolean comparison: compare if in each row autos[‘name’].str[1] is in autos[‘brand’] series.
I have no idea how I can process those strings with this method further.
I can’t use “If” statements: they are not allowed
I tried to use str.replace with regex: but I didn’t learn about it, so I don’t know how to use it .
No idea how to solve it