Pandas DataFrame 取一行数据会得到Series的方法
作者:siml142857 时间:2023-08-28 04:25:13
Pandas DataFrame 取一行数据会得到Series的方法
如题,想要取如下dataframe的一行数据,以为得到的还是dataframe
lista = [1, 3, 7,4,0]
listb = [3, 3, 4,4,5]
listc = [3, 3, 4,4,6]
df1 = pd.DataFrame({'col1':lista,'col2':listb,'colb':listc})
print(df1)
print(df1.loc[0,:])
print(type(df1.loc[0,:]))
因为这里得到的是一维数据,结果得到的Series
然后用to_frame() 转换一下,发现并没有什么用,变成了单列的DataFrame,而不是单行
df2=df1.loc[0,:].to_frame()
print(df2)
来源:https://blog.csdn.net/u014428224/article/details/81871701
标签:Pandas,DataFrame,Series
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python在Windows下获取USB PID&VID的方法
2021-02-15 19:31:20
Pytorch参数注册和nn.ModuleList nn.ModuleDict的问题
2021-02-10 23:43:06
pandas中merge()函数的用法解读
2023-10-02 08:49:46
python3实现带多张图片、附件的邮件发送
2023-05-11 06:51:10
Python接收Gmail新邮件并发送到gtalk的方法
2022-03-05 22:39:01
深入理解Python中的元类(metaclass)
2021-02-25 22:10:00
mysql 8.0.17 安装配置图文教程
2024-01-14 11:44:16
![](https://img.aspxhome.com/file/2023/7/128037_0s.png)
css实现图片倒影效果
2007-11-05 18:29:00
![](https://img.aspxhome.com/file/UploadPic/200711/5/2007115184648157s.jpg)
python读写ini文件示例(python读写文件)
2023-06-21 03:10:14
OpenCV中图像通道操作的深入讲解
2022-02-13 02:39:22
![](https://img.aspxhome.com/file/2023/0/121390_0s.jpg)
redis查看连接数及php模拟并发创建redis连接的方法
2023-11-16 11:47:14
Python画图小案例之小雪人超详细源码注释
2021-09-21 11:49:44
Python深度学习pyTorch权重衰减与L2范数正则化解析
2021-03-18 11:39:01
![](https://img.aspxhome.com/file/2023/8/130758_0s.png)
解决Pandas生成Excel时的sheet问题的方法总结
2021-01-13 14:24:44
![](https://img.aspxhome.com/file/2023/6/87486_0s.png)
python标准库random模块处理随机数
2023-11-23 16:22:49
NodeJs读取JSON文件格式化时的注意事项
2024-05-02 17:37:03
Python 中导入文本文件的示例代码
2021-04-18 04:53:01
php中session_unset与session_destroy的区别分析
2023-07-17 21:34:56
如何把Recordset转换成彩色的XML文件?
2009-11-02 20:22:00
如何尽快释放掉Connection对象建立的连接?
2009-12-16 18:38:00