当前位置:网站首页>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()
边栏推荐
- 信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
- The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track
- Usage of '...' in golang
- Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
- 文件操作(一)——文件简介与文件的打开方式和关闭
- Win11更改磁盘驱动器号的方法
- [translation] safety. Value of sboms
- Method of manually cloning virtual machine in esxi6.7
- Neo4j 导入csv数据报错:Neo4j load csv error : Couldn‘t load the external resource
- Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
猜你喜欢
![[steering wheel] tool improvement: common shortcut key set of sublime text 4](/img/51/fe95e95ccd5cd6406f3b49e3bdba3f.png)
[steering wheel] tool improvement: common shortcut key set of sublime text 4

Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 1)

Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?

How to effectively prevent others from wearing the homepage snapshot of the website

Multithreaded programming

STM32——PWM学习笔记

FPGA_Vivado软件初次使用流程_超详细

朋友刚学完自动化测试就拿25Koffer,我功能测试何时才能到头?

【C进阶】深入探索数据的存储(深度剖析+典例解读)

这种动态规划你见过吗——状态机动态规划之股票问题(上)
随机推荐
assert _ Aligns
JVM memory model parsing
How to close the case prompt icon of win11? Closing method of win11 case prompt Icon
Influence of middle tap change on ZVS oscillation circuit
Anti electronic ink screen st7302
ES6 advanced - using prototype object inheritance methods
Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
STM32——串口学习笔记(一个字节、16位数据、字符串、数组)
[SQL] CASE表达式
Safety margin of mass consumption
Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
Chapter 3 business function development (delete clues)
Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
规范自己debug的流程
MySQL教程:MySQL数据库学习宝典(从入门到精通)
MySQL build websites data table
Teach you to rely on management hand in hand
1. Software testing ----- the basic concept of software testing
小测(一)
Image recognition (VII) | what is the pooling layer? What's the effect?