Apr-16-2026, 07:40 PM
Hello:
I received a list for a user that needs to be reformatted. Need to pluck data out of prior rows.
This code demonstrates the issue:
The above code only adds the Make to the first row of the models.
manufacturor need to be populated for all model rows.
Know I am close, but do not know how to proceed.
Thanks for your attention to this matter.
KD
I received a list for a user that needs to be reformatted. Need to pluck data out of prior rows.
This code demonstrates the issue:
import numpy as np
import os
import pandas as pd
df = pd.DataFrame({'Make/Model': ['FORD', 'BRONCO', 'MAVERICK', 'MUSTANG', 'HONDA', 'CIVIC', 'CR-V', 'HYUNDAI', 'TUCSON', 'ELANTRA', 'TOYOTA', 'CAMERY', 'AVALON'],
'firstYear': [np.nan, 1965.0, 1970.0, 1964.0, np.nan, 1972.0, 1995.0, np.nan, 2004.0, 1990.0, np.nan, 1982.0, 2000.0],
'style': [np.nan, 'suv', 'compact', 'sport', np.nan, 'compact', 'suv', np.nan, 'suv', 'compact', np.nan, 'sedan', 'sedan'],
'number doors': [np.nan, '2, 4', '2,4 ', '2', np.nan, '2, 4', '4', np.nan, '4', '4', np.nan, '4', '4'],
'manufacturor': [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]})
df['manufacturor'] = np.where(df['firstYear'].shift(1).isna() & df['style'].shift(1).isna() == True ,
df['Make/Model'].shift(1), df['manufacturor'].shift(1) )The Make/Model attribute contains two data types, need to add the Make to the Model rows.The above code only adds the Make to the first row of the models.
manufacturor need to be populated for all model rows.
Know I am close, but do not know how to proceed.
Thanks for your attention to this matter.
KD
