您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用适当的列值将pandas.core.series.Series转换为数据框python

使用适当的列值将pandas.core.series.Series转换为数据框python

您非常亲密,首先to_frame通过T

s = pd.Series([1159730, 1], index=['product_id_y','count'], name=6159402)
print (s)
product_id_y    1159730
count                 1
Name: 6159402, dtype: int64

df = s.to_frame().T
print (df)
         product_id_y  count
6159402       1159730      1
df = s.rename(None).to_frame().T
print (df)
   product_id_y  count
0       1159730      1

DataFrame构造函数的另一个解决方案:

df = pd.DataFrame([s])
print (df)
         product_id_y  count
6159402       1159730      1
df = pd.DataFrame([s.rename(None)])
print (df)
   product_id_y  count
0       1159730      1
python 2022/1/1 18:36:57 有278人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶