具有组内值的新列(New column with a value inside a group)
A B C 0 Red 2002-01-13 3.9 1 Red 2002-01-13 4.1 2 Red 2002-01-13 2.3 3 Red 2002-01-14 0.7 4 Red 2002-01-14 5.9 5 Red 2002-01-14 3.0 6 Red 2002-01-15 6.9 7 Red 2002-01-15 6.4 8 Red 2002-01-15 9.9 9 Blue 2006-07-21 7.2 10 Blue 2006-07-21 4.2 11 Blue 2006-07-21 6.1 12 Blue 2006-07-22 0.1 13 Blue 2006-07-22 3.2 14 Blue 2006-07-22 2.7
我想用下一个条件创建一个
df['D']
列:
- 取每个
A
组的第一个B
日期的最后一个C
值。我的意思是,对于
A
组Red
,取2.3,因为它是第一个B
date2002-01-13
的最后一个C
值。 对于A
组Blue
,取6.1,因为它是2006-07-21
第一个B
日期的最后一个C
值。输出应该是:
A B C D 0 Red 2002-01-13 3.9 2.3 1 Red 2002-01-13 4.1 2.3 2 Red 2002-01-13 2.3 2.3 3 Red 2002-01-14 0.7 2.3 4 Red 2002-01-14 5.9 2.3 5 Red 2002-01-14 3.0 2.3 6 Red 2002-01-15 6.9 2.3 7 Red 2002-01-15 6.4 2.3 8 Red 2002-01-15 9.9 2.3 9 Blue 2006-07-21 7.2 6.1 10 Blue 2006-07-21 4.2 6.1 11 Blue 2006-07-21 6.1 6.1 12 Blue 2006-07-22 0.1 6.1 13 Blue 2006-07-22 3.2 6.1 14 Blue 2006-07-22 2.7 6.1
我试过了:
df['D'] = df.groupby('A')["C"].transform('last')
A B C 0 Red 2002-01-13 3.9 1 Red 2002-01-13 4.1 2 Red 2002-01-13 2.3 3 Red 2002-01-14 0.7 4 Red 2002-01-14 5.9 5 Red 2002-01-14 3.0 6 Red 2002-01-15 6.9 7 Red 2002-01-15 6.4 8 Red 2002-01-15 9.9 9 Blue 2006-07-21 7.2 10 Blue 2006-07-21 4.2 11 Blue 2006-07-21 6.1 12 Blue 2006-07-22 0.1 13 Blue 2006-07-22 3.2 14 Blue 2006-07-22 2.7
I want to create a
df['D']
column, with next condition:
- Take the last
C
value of the firstB
date, by eachA
group.I mean, for
A
groupRed
, take 2.3, as it is the lastC
value of firstB
date2002-01-13
. ForA
groupBlue
, take 6.1, as it is the lastC
value of firstB
date2006-07-21
.Output should be:
A B C D 0 Red 2002-01-13 3.9 2.3 1 Red 2002-01-13 4.1 2.3 2 Red 2002-01-13 2.3 2.3 3 Red 2002-01-14 0.7 2.3 4 Red 2002-01-14 5.9 2.3 5 Red 2002-01-14 3.0 2.3 6 Red 2002-01-15 6.9 2.3 7 Red 2002-01-15 6.4 2.3 8 Red 2002-01-15 9.9 2.3 9 Blue 2006-07-21 7.2 6.1 10 Blue 2006-07-21 4.2 6.1 11 Blue 2006-07-21 6.1 6.1 12 Blue 2006-07-22 0.1 6.1 13 Blue 2006-07-22 3.2 6.1 14 Blue 2006-07-22 2.7 6.1
I've tried:
df['D'] = df.groupby('A')["C"].transform('last')
原文:https://stackoverflow.com/questions/51450485
更新时间:2024-04-22 21:04
最满意答案
您可以使用Gmail API检索附件: https : //developers.google.com/gmail/api/v1/reference/users/messages/attachments/get#examples
You can use Gmail API to retrieve attachments: https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get#examples
相关问答
更多-
您可以使用Gmail API检索附件: https : //developers.google.com/gmail/api/v1/reference/users/messages/attachments/get#examples You can use Gmail API to retrieve attachments: https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get#examples
-
如何仅从特定Gmail邮件标签下载未读附件?(How do I download only unread attachments from a specific gmail label?)[2022-02-05]
尝试修改此行: resp, items = m.search(None, 'FROM', '"Impact Stats Script"') 至: resp, items = m.search(None, 'UNSEEN', 'FROM', '"Impact Stats Script"') Python imaplib文档仅显示添加更多搜索条件 , IMAP规范定义了UNSEEN搜索条件: UNSEEN Messages that do not have the \Seen flag set ... -
硬一个:-) import email, getpass, imaplib, os detach_dir = '.' # directory where to save attachments (default: current) user = raw_input("Enter your GMail username:") pwd = getpass.getpass("Enter your password: ") # connecting to the gmail imap server m = im ...
-
有关rebol / command的spop协议,请参见http://re-bol.com/prot-spop.r 。 我也有一个Rebol3的版本。 来自Saphir / Atronix的R3有https。 See http://re-bol.com/prot-spop.r for the spop protocol for rebol/command. I also have a version for Rebol3 somewhere. R3 from Saphir/Atronix has https ...
-
官方文档解释说您只能修改消息的标签 。 您将无法更新邮件正文。 无论如何,你需要做的是获取消息数据并保存它,然后删除消息 ,最后再次插入消息 ,删除附件。 我希望这个信息帮助! The official documentation explains that you can only modify the labels of the message. You won't be able to update the message body. In any case, what you are require ...
-
如何获取电子邮件附件元数据而不是Gmail中的内容?(How to get email attachment meta data but not the content from Gmail?)[2022-02-28]
最后,我放弃了AE.Net.Mail并转而使用Gmail API。 我可以从消息获取请求中获取附件元数据,而无需获取实际的附件文件。 https://developers.google.com/gmail/api/v1/reference/users/messages/get Eventually, I gave up on AE.Net.Mail and switched to Gmail API instead. And I am able to get attachment meta data fro ... -
我更喜欢将HTML用于此类目的。 您可以使用电子邮件中的锚标记为服务器上的文件指定链接。 要在电子邮件中编写HTML:
HTML email This email contains HTML Tags!
脚本下载电子邮件附件(script to download email attachments)[2021-08-23]
email模块包含一个函数message_from_bytes 。 使用它来代替message_from_string来解析bytes对象。 m = email.message_from_bytes(email_body) The email module includes a function message_from_bytes. Use that instead of message_from_string to parse a bytes object. m = email.message_fro ...ENOENT表示找不到文件 - 您的代码只接受files的第一个字符,当然 - 它不是有效的文件名。 要使用jython通过带有PDF附件的Gmail成功发送电子邮件,您可以使用: library(rJython) rJython <- rJython() rJython$exec( "import smtplib" ) rJython$exec("from email.MIMEMultipart import MIMEMultipart") rJython$exec("from email.MIMEBa ...那么您在Exchange 2007/2010环境中使用Outlook? 如果是,你冷看看EWS 。 So you are using outlook in an Exchange 2007/2010 environment? If yes you cold take a look at EWS.相关文章
更多- inside MPQ
- Becoming a data scientist
- [转]So You Want To Be A Producer
- SQL中GROUP BY与HAVING的用法
- 求一个group by后面字段顺序影响结果的例子
- Spring Data: a new perspective of data operations
- How to Start a Business in 10 Days
- A Great List of Windows Tools
- Create a Bootable MicroSD Card
- [译文] 恶意软件行为综述 - A View on Current Malware Behaviors
最新问答
更多- 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
- 高考完可以去做些什么?注意什么?
- Allauth不会保存其他字段(Allauth will not save additional fields)
- Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
- sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
- 怎么在《我的世界》游戏里面编程
- .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
- 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
- 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
- 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
- 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
- 如何使用变量值创建参数类(How to create a parameter class with variant value)
- 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
- 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
- rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
- 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
- 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
- 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
- CSS修复容器和溢出元素(CSS Fix container and overflow elements)
- 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
- 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
- SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
- 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
- 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
- Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
- 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
- 函数调用可以重新排序(Can function calls be reordered)
- 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
- 如何解释SBT错误消息(How to interpret SBT error messages)
- 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)