1

Does anyone know how to transform the following data frame?

value name
1 florida name
2 parkway address
3 Tampa city

into this one using Pandas library?

name address city
1 florida parkway Tampa

Just need to ignore indexes. Values from column name should become new columns and the final data frame should contain one row with corresponded values from the original value column.

P.S. I've already seen this one and this. But could not find an answer to my question there.

  • A = pd.DataFrame( ), inside of this parenthesis you have to add your data. To transpose your DataFrame A, you can use numpy and perform: A = np.transpose(A) or A.T – felixpradoh Mar 17 '21 at 07:56
  • [Félix del Prado Hurtado](https://stackoverflow.com/users/11143153/f%c3%a9lix-del-prado-hurtado) but I don't want to have indexes as column names. The goal is to have values from the original `name` column to be new column names. – Dmitry Shinelev Mar 17 '21 at 08:01
  • I am not very sure about your concept. also adding some code to the post will help. Think about the dataframe as a matrix, where row=index and columns=columns. You can rename these indexes or columns. – felixpradoh Mar 17 '21 at 08:05
  • `df.pivot_table(columns="name", values="value", index=None, aggfunc="first").reset_index(drop=True)` – Rob Raymond Mar 17 '21 at 08:06
  • @RobRaymond thanks, this code works for me, and do what I need – Dmitry Shinelev Mar 17 '21 at 08:29
  • @FélixdelPradoHurtado Rob's comment helps to solve the problem. – Dmitry Shinelev Mar 17 '21 at 08:32

0 Answers0