Мне удалось получить другой вариант, немного быстрее, чем предыдущий:
df = pd.read_csv(path)
df.drop(columns=['Year', 'Month', 'Day'], inplace=True)
df.drop_duplicates(inplace=True)
df.reset_index(drop=True, inplace=True)
dataset_names = df['Dataset']
dataset_names.drop_duplicates(inplace=True)
dataset_names.reset_index(drop=True, inplace=True)
def df_new_column(list_names, value):
row_list = []
for dataset in list_names:
dictionary = {}
row = {'Field': value,
'Type': 'string',
'Dataset': dataset}
dictionary.update(row)
row_list.append(dictionary)
data = pd.DataFrame(row_list)
return data
year = df_new_column(dataset_names, 'YEAR')
year = df.append(year, ignore_index=True, verify_integrity=True, sort=True)
month = df_new_column(dataset_names, 'MONTH')
month = year.append(month, ignore_index=True, verify_integrity=True, sort=True)
day = df_new_column(dataset_names, 'DAY')
day = month.append(day, ignore_index=True, verify_integrity=True, sort=True)
И время:
Над решением:
real 0m0,433s
user 0m0,722s
sys 0m0,605s
ответ Джима Эйзенберга:
real 0m0,546s
user 0m0,907s
sys 0m0,531s