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)
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.