pandas pd.read_csv()函数中parse_dates()参数的用法说明
作者:MR_jie1 时间:2023-07-22 04:51:26
parse_dates : boolean or list of ints or names or list of lists or dict, default False
boolean. If True -> try parsing the index.
list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column.
list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column.
dict, e.g. {‘foo' : [1, 3]} -> parse columns 1, 3 as date and call result ‘foo'
If a column or index contains an unparseable date, the entire column or index will be returned unaltered as an object data
type. For non-standard datetime parsing, use pd.to_datetime after pd.read_csv
中文解释:
boolean. True -> 解析索引
list of ints or names. e.g. If [1, 2, 3] -> 解析1,2,3列的值作为独立的日期列;
list of lists. e.g. If [[1, 3]] -> 合并1,3列作为一个日期列使用
dict, e.g. {‘foo' : [1, 3]} -> 将1,3列合并,并给合并后的列起名为"foo"
补充:解决Pandas的to_excel()写入不同Sheet,而不会被重写
在使用Pandas的to_excel()方法写入数据时,当我们想将多个数据写入一个Excel表的不同DataFrame中,虽然能够指定sheet_name参数,但是会重写整个Excel之后才会存储。
import pandas as pd
现在我有三个DataFrame,分别是大众某车型的配置、外观和内饰数据。现在我想要将这三个DF存入一张表的不同sheet中
>>> df1
220V车载电源 A/C开关 ACC Autohold Aux BMBS爆胎监测与安全控制系统 CD机 CarPlay
0 0 0 0 0 0 0 1
>>> df2
A柱 B柱 C柱 保险杠 倒车灯 倒车镜尺寸 前后灯 前脸 前风窗玻璃 后视镜尺寸
0 0 0 0 0 0 0 0 0 0
>>> df3
HUD抬头数字显示 中控台 中控锁 中控面板 中间扶手 仪表盘 儿童安全座椅接口 全景天窗 分辨率 后排出风口
0 0 4 5 0 0 13 0 0 0
一般情况下:
df1.to_excel("大众.xlsx",sheet_name="配置")
df2.to_excel("大众.xlsx",sheet_name="外观")
df3.to_excel("大众.xlsx",sheet_name="内饰")
可是结果中:
只有最后一个存储的内饰数据,并不符合我们的需求。
解决方法:
writer = pd.ExcelWriter('大众.xlsx')
df1.to_excel(writer,"配置")
df2.to_excel(writer,"外观")
df3.to_excel(writer,"内饰")
writer.save()
结果:
实现插入相同Excel表中不同Sheet_name!
来源:https://blog.csdn.net/MR_jie1/article/details/88394870
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
在Django的通用视图中处理Context的方法
在ASP.NET 2.0中操作数据之二十三:基于用户对修改数据进行限制
![](https://img.aspxhome.com/file/2023/4/75524_0s.png)
python模拟表单提交登录图书馆
![](https://img.aspxhome.com/file/2023/5/65935_0s.png)
Win7环境下搭建Go开发环境(基于VSCode编辑器)
![](https://img.aspxhome.com/file/2023/0/130920_0s.png)
解决python运行启动报错问题
Spring @Enable模块驱动原理及使用实例
IE和Firefox的js兼容性整理
Mysql 如何查询时间段交集
sqlserver 数据库压缩与数据库日志(ldf)压缩方法分享
python实现马丁策略回测3000只股票的实例代码
![](https://img.aspxhome.com/file/2023/3/109503_0s.gif)
Python列表生成器的循环技巧分享
![](https://img.aspxhome.com/file/2023/8/63238_0s.png)
一篇文章让你搞清楚JavaScript事件循环
![](https://img.aspxhome.com/file/2023/5/136045_0s.png)
php基础字符串与数组知识点讲解
如何制作K线图?
python爬虫之urllib3的使用示例
基于python实现高速视频传输程序
python 实现围棋游戏(纯tkinter gui)
![](https://img.aspxhome.com/file/2023/4/92074_0s.gif)
linux mysql5.5升级至mysql5.7的步骤与踩到的坑
![](https://img.aspxhome.com/file/2023/4/115344_0s.png)
一文带你熟悉Go语言中函数的使用
PHP字典树(Trie树)定义与实现方法示例
![](https://img.aspxhome.com/file/2023/1/55821_0s.png)