当前位置:网站首页>dataframe整理:datetime格式分拆;删除特定行;分组整合。
dataframe整理:datetime格式分拆;删除特定行;分组整合。
2022-07-26 03:03:00 【八点十面】
导入CSV格式数据,并将年月日分开。
将csv格式数据导入为dataframe格式。
并且,将date columne中的年月日分拆。
首先确保date columne中的格式是datetime格式。
import pandas as pd
#pd.set_option('display.max_rows', None)
df = pd.read_csv(r"D:\xxx.csv",parse_dates=["date"])
df["year"] = df.date.apply(lambda x:x.year)
df["month"] = df.date.apply(lambda x:x.month)
df["day"] = df.date.apply(lambda x:x.day)
删除特定行
将每一行中某一columne如果为0,则删除该行。
df=df.drop(df[df["xxx"] == 0].index)
根据年和月进行分组
使用groupby函数。并且针对size columne进行求和。
month_size = df["size"].groupby([df["year"],df["month"]]).sum()
day_size = df["size"].groupby([df["year"],df["month"],df["day"]]).sum()
边栏推荐
- [SQL] 自连接的用法
- [steering wheel] tool improvement: common shortcut key set of sublime text 4
- Win11 method of changing disk drive letter
- AMD64 (x86_64) architecture ABI document: medium
- STM32——DMA笔记
- 如何有效的去防止别人穿该网站首页快照
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
- 如何根据登录测试的需求设计测试用例?
- Chapter 3 business function development (delete clues)
- 【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(Live Template&Postfix Completion篇)
猜你喜欢

这种动态规划你见过吗——状态机动态规划之股票问题(上)

How to design automated test cases?

1.软件测试-----软件测试的基本概念

Arthas' dynamic load class (retransform)

Masscode is an excellent open source code fragment manager

如何用U盘进行装机?

(九)属性自省

软件测试岗:阿里三面,幸好做足了准备,已拿offer

How to design test cases according to the requirements of login testing?

ES6 advanced - using prototype object inheritance methods
随机推荐
【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(Live Template&Postfix Completion篇)
Zhimeng prompts you how to solve the problem of setting the field as linkage type
Difference between soft link and hard link
移位距离和假设的应用
GoLang日志编程系统
[translation] safety. Value of sboms
万维网、因特网和互联网的区别
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)
Study notes of pytorch deep learning practice: convolutional neural network (Advanced)
Unity快速搭建城市场景
Standardize your own debug process
案例:使用keepalived+Haproxy搭建Web群集
1. Software testing ----- the basic concept of software testing
Jenkins' study notes are detailed
Shardingsphere data slicing
【方向盘】工具提效:Sublime Text 4的常用快捷键合集
GoLang 抽奖系统 设计
STM32 - PWM learning notes
Article setting top
软件测试岗:阿里三面,幸好做足了准备,已拿offer