У меня есть раздел питона кода, как показано ниже:оптимизации контура в Python с использованием локация команды
# Main Loop that take values attributed to the row by row basis and sorts
# them into correpsonding columns based on matching the 'Name' and the newly
# generated column names.
listed_names=list(df_cv) #list of column names to reference later.
variable=listed_names[3:] #List of the 3rd to the last column. Column 1&2 are irrelevant.
for i in df_cv.index: #For each index in the Dataframe (DF)
for m in variable: #For each variable in the list of variable column names
if df_cv.loc[i,'Name']==m: #If index location in variable name is equal to the variable column name...
df_cv.loc[i,m]=df_cv.loc[i,'Value'] #...Then that location is equal to the value in same row under the column 'Value'
В основном она принимает список 3XN времени/имя/значение и сортирует его в панд ФР размера п от уникальный (п).
Time Name Value
1 Color Red
2 Age 6
3 Temp 25
4 Age 1
В это:
Time Color Age Temp
1 Red
2 6
3 25
4 1
Мой код взять очень долгое количество времени, чтобы бежать, и я хотел бы знать, если есть лучший способ настроить свои циклы. Я пришел из фона MATLAB, поэтому стиль python (т.е. не используя строки/столбцы для все по-прежнему инопланетен).
Как сделать этот раздел кода быстрее?