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="内饰")

可是结果中:

pandas pd.read_csv()函数中parse_dates()参数的用法说明

只有最后一个存储的内饰数据,并不符合我们的需求。

解决方法:


writer = pd.ExcelWriter('大众.xlsx')
df1.to_excel(writer,"配置")
df2.to_excel(writer,"外观")
df3.to_excel(writer,"内饰")
writer.save()

结果:

pandas pd.read_csv()函数中parse_dates()参数的用法说明

实现插入相同Excel表中不同Sheet_name!

来源:https://blog.csdn.net/MR_jie1/article/details/88394870

标签:pandas,pd.read,csv,parse,dates
0
投稿

猜你喜欢

  • 在Django的通用视图中处理Context的方法

    2023-02-25 20:50:45
  • 在ASP.NET 2.0中操作数据之二十三:基于用户对修改数据进行限制

    2023-07-12 08:52:20
  • python模拟表单提交登录图书馆

    2021-11-06 19:20:42
  • Win7环境下搭建Go开发环境(基于VSCode编辑器)

    2024-04-30 09:59:04
  • 解决python运行启动报错问题

    2022-08-13 06:44:15
  • Spring @Enable模块驱动原理及使用实例

    2023-11-07 10:11:51
  • IE和Firefox的js兼容性整理

    2007-11-21 19:40:00
  • Mysql 如何查询时间段交集

    2024-01-22 09:27:32
  • sqlserver 数据库压缩与数据库日志(ldf)压缩方法分享

    2024-01-17 12:33:46
  • python实现马丁策略回测3000只股票的实例代码

    2023-03-02 01:12:29
  • Python列表生成器的循环技巧分享

    2023-10-06 21:24:28
  • 一篇文章让你搞清楚JavaScript事件循环

    2024-04-19 09:53:02
  • php基础字符串与数组知识点讲解

    2023-05-25 08:28:14
  • 如何制作K线图?

    2010-06-29 17:25:00
  • python爬虫之urllib3的使用示例

    2023-01-24 07:40:03
  • 基于python实现高速视频传输程序

    2022-04-01 02:14:17
  • python 实现围棋游戏(纯tkinter gui)

    2023-11-23 16:13:04
  • linux mysql5.5升级至mysql5.7的步骤与踩到的坑

    2024-01-21 17:09:08
  • 一文带你熟悉Go语言中函数的使用

    2023-07-13 08:22:23
  • PHP字典树(Trie树)定义与实现方法示例

    2023-11-15 00:39:50
  • asp之家 网络编程 m.aspxhome.com