Upcasting Link to official Docs Have you ever run into a scenario where you have set your column type to int but when you go to display it either in a report or visualization it comes out a float? This happens because of something called upcasting. "Types can potentially be upcasted when combined with other types, meaning they are promoted from the current type (e.g. int to float)." Lets start with a DataFrame of 1 column and 8 rows where the values are random numbers from the normal distribution. >>> import pandas as pd >>> import numpy as np >>> df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32') >>> df1 A 0 0.406792 1 0.810450 2 1.161985 3 -1.402411 4 1.385434 5 -1.091746 6 0.018586 7 -0.606741 Now lets create a 3x8 DataFrame >>> df2 = pd.DataFrame( dict( A =...
Comments
Post a Comment