During one of the lessons I created a pivot table of which the int values became float.
I researched about it on the internet for quite some time and I guess it was due to that one of the values became nan which transformed them all to float (my guess, correct me if I am wrong, please)
So I tried to solve it by using fillna, but it didn’t solve anything about the dtype.
I tried to check on the internet how could I change it back and I found “astype(int)” which was shown with a lot of df but none with pivot. So I tried to put that astype(int) to all the places I thought could make any sense and tried separately with shoe_counts_pivot[“id”] as well hoping that python will remember that the values came from that column (which was just silly but was worth a try haha)
In the end I just changed the type of each column separately, but with many columns this would be pretty painful.
So I am pretty sure this can be solved so much easier than I did it and I am wondering if anyone could assist me with this
Also as a plus request if I did the above code (the astype(int) with all the colors) as a loop which is ridiculous I know but I am curious, how would I be able to do that?
Knowing the pivot table looks like this:
Hi there and thank you for your reply!
With all respect I do want to point out that there is a nan value… After I ran your code as well the pivot table is as follows:
As you can see in here wedges-black is a nan value.
Also if you just print the orders table you can see that it really does not have black wedges in the original table either:
As I used fillna on my pivot table mine has 0 at that value that you have seen in my original post. I wished to achieve that look with less code about converting the float into int as I had to write all my columns’ names there to switch them back to int.
Obviously having it float instead of being int is not going to change anything with calculations but with integers it is much more aesthetic for which I wanted to find an easier way than mine to rewrite these values on this pivot table to int.
And I do really appreciate that you’re trying to help me, so thank you!!