0

I have a list that contain the columns names of of one table. Now what i am trying to do is i am getting column values from one table and are trying to make it column names of another table.

List contain colnames of one table

v = list(df_new.columns.values)

and i am getting column values in loop from another and trying to replace it with names in list.

for column in df_img_attr_name_type['Attribute_Name']:
        df_new = df_new.rename(columns = {v[1:2]:column})

i want col_name = 1,2,3,4 to be col_name = A, B, C, D

skhan
  • 199
  • 10
  • 3
    please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – skhan Jul 24 '19 at 14:19
  • v = list(df_new.columns.values) for column in df_img_attr_name_type['Attribute_Name']: df_new = df_new.rename(columns = {v[1016]:column}) – Ameer Hamza Jul 24 '19 at 14:23
  • Please have a look at [how-to-make-good-reproducible-pandas-examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples), if the question has a reproducible example, it is easier to understand and provide a solution, – harvpan Jul 24 '19 at 14:31

1 Answers1

0

If I understand correctly, you have a dataframe with values which you want to use as columns for another dataframe? If df contains the column names and df_new is the target dataframe, a loop can work:

for i in df['Attribute Names']:
    df_new[i] = None

This only works if all values in Attribute Names are strings, and it doesn't populate anything.

Jim Eisenberg
  • 1,490
  • 1
  • 9
  • 17