Choose correct datatype when creating new dataframe column from old ones · Issue #8527 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
I am converting a Stata dataset to a dataframe, then multiply two columns to create a third one. The chosen datatype for the two columns is int8 and for some reason the new column blindly follows that.
For instance, this code
df = pd.read_stata(file) df['w_age_educ'] = df['w_age'] * df['weduc'] print(df[['w_age', 'weduc', 'w_age_educ']].dtypes) print(df[['w_age', 'weduc', 'w_age_educ']][:3])
would give me
w_age int8 weduc int8 w_age_educ int8 dtype: object w_age weduc w_age_educ 0 44 14 104 1 34 13 -70 2 33 18 82
Is this a bug or intended behavior? If the latter, how can I get my desired product column?