问题
I want to rename the columns from one dataframe into the columns of another, meanwhile creating a completely new dataframe. I am not really sure how to approach this and which is why the consultation. I want to take the name of one element in the string from one column and reuse it to another. This can be either in R or python, doesn't matter too much. The rest of the string values can be fixed values.
Such as: Hm106_120.region001 1813 PKSI_GCF1813 Streptomyces_sp_Hm106 MBT13_26.region001 1813 PKSI_GCF1813 Streptomyces_sp_MBT13
Please see the example in the picture posted for better description
Thanks for the help :)Table Rename
回答1:
df2 = df1.copy()
df2.rename(columns={"GCF No": "GCF"}, inplace=True)
df2['GCF'] = 'PKSI_GCF' + df2['GCF'].astype(str)
df1[['BGC','BGC2']] = df1['BGC'].str.split('_',expand=True)
df2['Genome'] = 'Streptomyces_sp_' + df1['BGC'].astype(str)
df2.set_index('GCF', inplace=True)
来源:https://stackoverflow.com/questions/59822507/rename-columns-of-one-dataframe-to-another-r-or-python