程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用适当的列值将pandas.core.series.Series转换为数据框python大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

开发过程中遇到使用适当的列值将pandas.core.series.Series转换为数据框python的问题如何解决?下面主要结合日常开发的经验,给出你关于使用适当的列值将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

解决方法

我正在运行一个函数,其中的变量是pandas.core.series.Series类型。

type of the series shown below.

<class 'pandas.core.series.Series'>
product_id_y    1159730
count                 1
Name: 6159402,dtype: object

我想将其转换为数据框,这样,我得到

product_id_y    count
1159730           1

我试图这样做:

series1 = series1.to_frame()

但是得到错误的结果

转换为数据框后

              6159402
product_id_y  1159730
count               1

完成重置索引后,我 series1 = series1.reset_index()

           index  6159402
 0  product_id_y  1159730
 1         count        1

还有其他其他方法吗?

@H_618_68@@H_618_68@
@H_618_68@

大佬总结

以上是大佬教程为你收集整理的使用适当的列值将pandas.core.series.Series转换为数据框python全部内容,希望文章能够帮你解决使用适当的列值将pandas.core.series.Series转换为数据框python所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。