首页
学习
活动
专区
圈层
工具
发布
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    Pandas 数据分析: 3 种方法实现一个实用小功能

    Pandas 的强大体现在其简洁,解决一些数据分析问题非常方便。 今天解释一个实用的小功能,或许日后工作学习中会用到。 求两列时分(HH:mm)表示数据的分钟数差值。...使用pandas读入数据:使用的 pandas 版本为 0.25.1 df = pd.read_excel('test_date_subtract.xlsx') df ?...3 转为 DatetimeIndex 转化为 DatetimeIndex 类型后,直接获取 hour 和 minute 属性: atime = pd.DatetimeIndex(df['a']) btime...= pd.DatetimeIndex(df['b']) df['amins'] = atime.hour * 60 + atime.minute df['bmins'] = btime.hour *...5 总结 以上就是使用 pandas 三种方法求解时分表示数据的分钟数差值,使用到的 API 包括: to_datetime 转化为日期时间 datetime 类型列的 dt 访问器 DatetimeIndex

    57820

    Python可视化数据分析06、Pandas进阶

    Python可视化数据分析06、Pandas进阶 前言 博客:【红目香薰的博客_CSDN博客-计算机理论,2022年蓝桥杯,MySQL领域博主】 ✍本文由在下【红目香薰】原创,首发于CSDN✍...repository/pypi/simple pip3 config list pip3 install --upgrade pip pip3 install requests pip3 install pandas...把一个时间字符串string解析为时间 print(datetime.datetime.strptime("2022-7-27 19:19:17", "%Y-%m-%d %H:%M:%S")) 时间序列 Pandas...Pandas最基本的时间序列类型就是以时间戳(TimeStamp)为index元素的Series类型。 时间序列只是index比较特殊的Series,因此一般的索引操作对时间序列依然有效。...import datetime as datetime import pandas as pd import numpy as np from pandas import Series print("

    75120

    数据导入与预处理-拓展-pandas时间数据处理01

    通过这个简单的例子,就能够容易地总结出官方文档中的这个表格: 概念 单元素类型 数组类型 pandas数据类型 Date times Timestamp DatetimeIndex datetime64...时间戳(Date times)的构造与属性 概念 单元素类型 数组类型 pandas数据类型 Date times Timestamp DatetimeIndex datetime64[ns] Time...(['2020-12-21', '2020-12-22', '2020-12-23'], dtype='datetime64[ns]', freq=None) pandas.core.indexes.datetimes.DatetimeIndex...'> # 多个时间数据,将会转换为pandas的DatetimeIndex 输出为: 时间戳格式转换 在极少数情况,时间戳的格式不满足转换时,可以强制使用format进行匹配: temp =...Series,因此返回的是DatetimeIndex,如果想要转为datetime64[ns]的序列,需要显式用Series转化: # DatetimeIndex # DatetimeIndex(['2020

    7.4K10

    【Python报错已解决】`TypeError`:`TypeError: not enough arguments for format string`

    想成为一名优质的博主那么这篇专栏你一定要去了解 引言 在Python编程中,TypeError是一个常见的错误类型,它表示在操作或函数调用中使用了错误的类型。...本文将探讨一个具体的TypeError:TypeError: not enough arguments for format string。我们将通过逐步推理分析,提出有针对性的解决方案。...尝试使用错误的参数数量进行字符串格式化 formatted_string = "The answer is %d" % 42 上面的代码试图使用一个格式化字符串来创建一个格式化的字符串,但由于提供的参数数量不正确,会导致TypeError...1.2 报错分析 错误信息可能如下: TypeError: not enough arguments for format string 这个错误通常发生在尝试使用旧式的字符串格式化方法(如%操作符)时

    27500

    【Python报错已解决】`TypeError`:`TypeError: string indices must be integers`

    想成为一名优质的博主那么这篇专栏你一定要去了解 引言 在Python编程中,TypeError是一个常见的错误类型,它表示在操作或函数调用中使用了错误的类型。...本文将探讨一个具体的TypeError:TypeError: string indices must be integers。我们将通过逐步推理分析,提出有针对性的解决方案。...尝试使用字符串索引访问字符,但使用了错误的索引类型 character = my_string["two"] 上面的代码试图使用一个字符串索引来访问字符串中的字符,但由于使用了错误的索引类型(字符串而不是整数),会导致TypeError...1.2 报错分析: 错误信息可能如下: TypeError: string indices must be integers or slices, not str 这个错误通常发生在尝试使用非整数类型(...四 总结 当遇到TypeError: string indices must be integers错误时,通常意味着我们尝试使用非整数类型作为字符串的索引。

    82710

    数据分析 ——— pandas日期处理(五)

    通过之前的文章,大家对pandas都有了基础的了解,在接下来的文章中就是对pandas的一些补充,pandas对日期处理函数。...一、pandas日期功能 1) 创建一个日期范围 通过指定周期和频率来使用date.range()函数,默认频率为/天 # pandas日期处理 import pandas as pd import...numpy as np # data.range() 创建日期序列 print(pd.date_range('1/1/2011', periods=5)) """ 输出: DatetimeIndex...2)更改日期频率 # 更改日期频率 # 按月,输出每月的1号的前一天 print(pd.date_range('1/1/2011', periods=5, freq='M')) """ 输出: DatetimeIndex...()不同,它不包括周六和周天 # bdate_range() 商业日期范围,不包括周六和周天 print(pd.bdate_range('8/2/2019', periods=5)) """ 输出: DatetimeIndex

    1.6K10
    领券