Pandas pivot creates many NaN values in new columns

238
January 14, 2018, at 08:56 AM

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.

Rent Charter Buses Company
READ ALSO
Jupyter notebook become RTL after upgrade

Jupyter notebook become RTL after upgrade

I created python 36 environment in miniconda

245
Multiplying matrices of different dtype

Multiplying matrices of different dtype

I am multiplying 2 matrices, Adot(B), where:

193
Python - Video4Linux2 - duplicate /dev/video0 to /dev/video1 in a script

Python - Video4Linux2 - duplicate /dev/video0 to /dev/video1 in a script

I have been making a mobile broadcasting solutionI intend to duplicate a device and run code in the middle and output it to /dev/video1

261
pandas dataframe to features and labels

pandas dataframe to features and labels

Here is a dataframe which I want to convert to features and label list/arrays

292