题目要求如下:

输入的数据为

要求按照日期查询出每日销售数量及相应产品的名称,并按照字符顺序进行排序。

下面是实现的代码:

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的更多相关文章

  1. [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 ...

  2. 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 ...

  3. LeetCode 893. Groups of Special-Equivalent Strings (特殊等价字符串组)

    题目标签:String 题目可以让在 偶数位置的 chars 互换, 也可以让 在 奇数位置的 chars 互换. 所以为了 return 正确的 group 数量,需要把 那些重复的 给排除掉. 可 ...

  4. 【LEETCODE】60、数组分类,适中级别,题目:75、560、105

    package y2019.Algorithm.array.medium; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.a ...

  5. Leetcode随缘刷题之寻找两个正序数组的中位数

    我一上来没读清题,想着这题这么简单,直接就上手写了: package leetcode.day_12_05; import java.util.ArrayList; import java.util. ...

  6. 数据库设计(二)Introduction to Database Design

    原文链接:http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html Introduction to Databa ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #415 (Div. 2) 翻车啦

    A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. 谈谈php里的DAO Model AR

    这次要谈的3个关键字:DAO.Model.AR,是我们在做web应用时常见的几个概念,也被称作设计模式(design pattern),先简单看看它们的全拼和中文: DAO:Data Access O ...

随机推荐

  1. CNN -- Simple Residual Network

    Smiling & Weeping ---- 我爱你,从这里一直到月亮,再绕回来 说明: 1.要解决的问题:梯度消失 2. 跳连接,H(x) = F(x)+x,张量维度必须一致,加完后再激活. ...

  2. scab2

    package com.cmb.cox.utils;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;im ...

  3. 一行超长日志引发的 “血案” - Containerd 频繁 OOM 背后的真相

    案发现场:混沌初现 2024年6月10日,本应是平静的一天.但从上午 9 点开始,Sealos 公有云的运维监控告警就开始不停地响.北京可用区服务器节点突然出现大量 "not ready&q ...

  4. Linux 增加 swap 分区

    检查当前swap分区 [root@localhost ~]# free -g total used free shared buffers cached Mem: 15 0 14 0 0 0 -/+ ...

  5. 颠覆传统编程,用ChatGPT十倍提升生产力

    我们即将见证一个新的时代!这是最好的时代,也是最坏的时代! 需求背景 背景: 平时会编写博客,并且会把这个博客上传到github上,然后自己买一个域名挂到github上. 我平时编写的博客会有一些图片 ...

  6. CLR via C# 笔记 -- 数组(16)

    1. 数组隐式继承 System.Array,所以数组是引用类型.变量包含的是对数组的引用,而不是包含数据本身的元素. 2. 数组协变性.将数组从一种类型转换为另一种类型. string[] sa = ...

  7. 大模型重塑软件开发,华为云AI原生应用架构设计与实践分享

    在ArchSummit全球架构师峰会2024上,华为云aPaaS平台首席架构师马会彬受邀出席,和技术爱好者分享AI原生应用引擎的架构与实践. AI大模型与AI重塑软件的大趋势下,软件会发生哪些本质的变 ...

  8. Tutorial: How to install GNU MCU Eclipse?

    Overview For more flexibility and upgradeability, GNU MCU Eclipse is not packed as a all-inclusive s ...

  9. Day 1 - 二分

    整数二分 我们可以做到每次排除一半的答案,时间复杂度 \(O(\log n)\). long long l = L, r = R; while(l <= r) { long long mid = ...

  10. 从输入URL到页面展示到底发生了什么?--01

    在浏览器中输入一个URL并按下回车键后,会发生一系列复杂且有条不紊的步骤,从请求服务器到最终页面展示在你的屏幕上.这个过程可以分为以下几个关键步骤: URL 解析 DNS 查询 TCP 连接 发送 H ...