简体   繁体   English

如何使这个不断变化的数据帧更快?

[英]how to make this changing dataframe faster?

list_nn = [k for k in list(df['job_keyword'].unique()) if not str(k).isdigit()]
i = 0
for  k in list_nn:
    df.loc[df.job_keyword == k ,'job_keyword'] = i
    df.loc[df.user_keyword == k , 'user_keyword'] = i
    i+=1

it's a loop through the data frame column and if its match with it change with number它是一个遍历数据框列的循环,如果它与它的匹配随数字变化
it takes more than 3 minutes is there a way to make this faster?需要超过 3 分钟有没有办法让它更快?

it's look though the entire dataframe I want to make it faster看起来虽然整个数据框我想让它更快

You can try something like the following:您可以尝试以下操作:

df[df.job_keyword.isin(list_nn)] = df[df.job_keyword.isin(list_nn)].index
df[df.user_keyword.isin(list_nn)] = df[df.job_keyword.isin(list_nn)].index

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM