pandas series.to-ag捕鱼王app官网

pandas series.to_frame()函数

作者:迹忆客 最近更新:2023/03/20 浏览次数:

python pandas series.to_frame() 函数将给定的 series 转换为 dataframe。

pandas.series.to_frame() 语法

series.to_frame(name=none)

参数

   
name 它是一个对象类型参数。它告诉我们,如果 series 有名称,那么传递的名称将代替 series 名称。

返回值

它返回一个代表 series 的 dataframe。

示例代码:series.to_frame() 方法将 series 转换为 dataframe

import pandas as pd
series = pd.series([ 'rose', 'jasmine', 'lili', 'tulip', 'hibiscus', 'sun flower', 'orchid', 'carnation','irises', 'gardenias'])
print("the original series is: \n")
print(series)
dataframe = series.to_frame()
print("the dataframe is: \n")
print(dataframe)

输出:

the original series is: 
0          rose
1       jasmine
2          lili
3         tulip
4      hibiscus
5    sun flower
6        orchid
7     carnation
8        irises
9     gardenias
dtype: object
the dataframe is: 
            0
0        rose
1     jasmine
2        lili
3       tulip
4    hibiscus
5  sun flower
6      orchid
7   carnation
8      irises
9   gardenias

该函数返回了代表给定 series 的 dataframe。

示例代码:series.to_frame() 方法将 series 转换为具有特定列名的 dataframe

import pandas as pd
series = pd.series([ 'rose', 'jasmine', 'lili', 'tulip', 'hibiscus', 'sun flower', 'orchid', 'carnation','irises', 'gardenias'])
print("the original series is: \n")
print(series)
dataframe = series.to_frame(name= 'flowers')
print("the dataframe is: \n")
print(dataframe)

输出:

the original series is: 
0          rose
1       jasmine
2          lili
3         tulip
4      hibiscus
5    sun flower
6        orchid
7     carnation
8        irises
9     gardenias
dtype: object
the dataframe is: 
      flowers
0        rose
1     jasmine
2        lili
3       tulip
4    hibiscus
5  sun flower
6      orchid
7   carnation
8      irises
9   gardenias

现在列名是 flowers

上一篇:

下一篇:pandas series.tolist() 函数

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

pandas read_csv()函数

发布时间:2024/04/24 浏览次数:254 分类:python

pandas read_csv()函数将指定的逗号分隔值(csv)文件读取到 dataframe 中。

pandas 追加数据到 csv 中

发布时间:2024/04/24 浏览次数:352 分类:python

本教程演示了如何在追加模式下使用 to_csv()向现有的 csv 文件添加数据。

pandas 多列合并

发布时间:2024/04/24 浏览次数:628 分类:python

本教程介绍了如何在 pandas 中使用 dataframe.merge()方法合并两个 dataframes。

pandas loc vs iloc

发布时间:2024/04/24 浏览次数:837 分类:python

本教程介绍了如何使用 python 中的 loc 和 iloc 从 pandas dataframe 中过滤数据。

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便
网站地图