Leetcode: 1484. Groups Sold Products By The Date
题目要求如下:
输入的数据为
要求按照日期查询出每日销售数量及相应产品的名称,并按照字符顺序进行排序。
下面是实现的代码:
import pandas as pd
def categorize_products(activities: pd.DataFrame) -> pd.DataFrame:
val = activities.drop_duplicates().groupby("sell_date")
return val.apply(lambda x:pd.Series([x["product"].count(),",".join(x["product"].sort_values())],index=["num_sold","products"])).reset_index()
代码的逻辑可以说非常简单。
先去重再按照日期进行排序,然后返回1个Series类型,在该类型中第1位是数量的统计,而第2位为排序后商品的名称。
最后是提交后的结果,超过17.9%的人,效率还有待加强。
Leetcode: 1484. Groups Sold Products By The Date的更多相关文章
- [LeetCode] 893. Groups of Special-Equivalent Strings 特殊字符串的群组
You are given an array A of strings. Two strings S and T are special-equivalent if after any number ...
- LeetCode 893 Groups of Special-Equivalent Strings 解题报告
题目要求 You are given an array A of strings. Two strings S and T are special-equivalent if after any nu ...
- LeetCode 893. Groups of Special-Equivalent Strings (特殊等价字符串组)
题目标签:String 题目可以让在 偶数位置的 chars 互换, 也可以让 在 奇数位置的 chars 互换. 所以为了 return 正确的 group 数量,需要把 那些重复的 给排除掉. 可 ...
- 【LEETCODE】60、数组分类,适中级别,题目:75、560、105
package y2019.Algorithm.array.medium; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.a ...
- Leetcode随缘刷题之寻找两个正序数组的中位数
我一上来没读清题,想着这题这么简单,直接就上手写了: package leetcode.day_12_05; import java.util.ArrayList; import java.util. ...
- 数据库设计(二)Introduction to Database Design
原文链接:http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html Introduction to Databa ...
- Codeforces Round#415 Div.2
A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...
- Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #415 (Div. 2) 翻车啦
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 谈谈php里的DAO Model AR
这次要谈的3个关键字:DAO.Model.AR,是我们在做web应用时常见的几个概念,也被称作设计模式(design pattern),先简单看看它们的全拼和中文: DAO:Data Access O ...
随机推荐
- postman Could not get any response 无法请求
外网访问接口地址,刚开始考虑到是阿里云服务器上面的ECS网络安全策略拦截,添加了白名单, 首先在浏览器中回车访问,页面有反应. 但是在postman中请求,仍然返回 Could not get any ...
- Filter过滤器进行统一参数处理demo
Filter过滤器进行统一参数处理demo import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet. ...
- tempcode排序
package com.hsy;import com.alibaba.fastjson.JSON;import org.springframework.util.CollectionUtils;imp ...
- 使用Kubesec检查YAML文件安全
目录 一.系统环境 二.前言 三.Kubesec简介 四.使用Kubesec检查YAML文件安全 五.总结 一.系统环境 本文主要基于Kubernetes1.22.2和Linux操作系统Ubuntu ...
- 06-Python类与对象
什么是类 百度百科: 类是对象的抽象,对象是对客观事物的抽象. 用通俗的话来说: 类是类别的意思,是数据类型. 对象是类别下的具体事物. 也就是说: 类是数据类型,对象是变量. 比如: 自定义一种数据 ...
- Shell读取整行
像C/C++,JAVA,Python等语言中,可以轻松地对文件进行按行读取. 那么,Shell中怎么实现对行读取呢? #!/bin/bash while read i do echo $i done ...
- Stable Diffusion(一)Stable Diffusion 原理
Stable Diffusion原理 此文为译文,原文见: https://stable-diffusion-art.com/how-stable-diffusion-work/ Stable Dif ...
- Python中使用MySQL模糊查询的方法
1.方法一:使用pymysql库的方法 当在Python中使用MySQL进行模糊查询时,我们通常会使用pymysql或mysql-connector-python这样的库来连接MySQL数据库并执行查 ...
- 使用EF 连接 数据库 SQLserver、MySql 实现 CodeFirst
1.新建项目,下载Nuget安装包 创建项目需要注意几点,如果是基于 .net framework 的项目 需要选择 相应版本的 EF, 如果是跨平台则选择EF Core版本. 我这里选择的是 .ne ...
- ABP框架开发实例教程-生成框架代码
ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称.ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB ...