我有一些数据透视代码因错误而失败
pandas.core.base.DataError:没有要聚合的数字类型
我已将问题追溯到之前的调用pandas.melt https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.melt.html
以下是熔化前的数据类型:
frame.dtypes
user_id Int64
feature object
seconds_since_start_assigned Int32
total float32
programme_ids object
q1 Int32
q2 Int32
q3 Int32
q4 Int32
q5 Int32
q6 Int32
q7 Int32
q8 Int32
q9 Int32
week Int32
现在开始融化
frame1 = pd.melt(
frame,
id_vars=['user_id', 'week'],
value_vars=['q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8', 'q9'],
var_name='question',
value_name='score')
frame1.dtypes
user_id object
week object
question object
score object
为什么打电话给melt
取代了Int32
我需要score
with object
?