0

I am working with a pandas dataframe that has the columns:

"product id" "price book" "list price currency" and "list price".

Each product is repeated up to 4 times with 3 different currencies. I did a pivot successfully so that there is now the column "product id" with unique product id's, with each List price and the currency in the same row.

I am now running into a problem when trying to add a fourth currency to the list, which will be "Intl". I am attempting to do this prior to the pivot step. This is what I used to append the values in the "List price currency" row, and it appears to have worked. Values in the row are successfully updated to "Intl" when they need to be when I print the dataframe.

datagrouped['List Price Currency'][df['Price Book Name'].str.contains("International",na=False)] = 'Intl'

Now when I try to do the pivot again and look at the table, it does indeed have a column for "Intl", however the dataframe is now filled with NaN values. This is what the pivot step of my code looks like.

df99 = datagrouped.drop_duplicates(['Product Code','List Price Currency'])

i = df99.pivot('Product Code', 'List Price Currency', 'List Price')\
     \
     .reset_index()\
     .rename_axis(None, 1)

enter image description here

I have checked and there should be prices in all columns for almost every product. What am I doing wrong along the way to get this final incorrect dataframe? Any guidance would be very appreciated.

Warthog1
  • 123
  • 1
  • 2
  • 9
  • 2
    Nope, you're wrong. If there are NaNs, then that means those entries don't exist. You cannot prove you are right, because you haven't shown your data. – cs95 Jan 14 '18 at 00:22
  • We dont trust you unless we have a proof for `there should be prices in all columns for almost every product`. Show us the data, incase of understanding things better go through this https://stackoverflow.com/questions/47152691/how-to-pivot-a-dataframe. – Bharath M Shetty Jan 14 '18 at 03:16

0 Answers0