- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
示例 Pandas 数据框:
ID Name COMMENT1 COMMENT2 NUM1 dan hi hello 11 dan you friend 23 jon yeah nope 32 jon dog cat .53 jon yes no .1
I am trying to create a dataframe that groups by ID and NAME that concatenates COMMENT1 and COMMENT2 that also sums NUM.
This is what I'm looking for:
ID Name COMMENT1 COMMENT2 NUM1 dan hi you hello friend 33 jon yeah yes nope no 3.12 jon dog cat .5
I tried using this:
input_df = input_df.groupby(['ID', 'NAME', 'COMMENT1', 'COMMENT2']).sum().reset_index()
但它不起作用。
如果我使用这个:
input_df = input_df.groupby(['ID']).sum().reset_index()
它对 NUM 列求和但忽略所有其他列。
最佳答案
让我们把它变成一行
df.groupby(['ID','Name'],as_index=False).agg(lambda x : x.sum() if x.dtype=='float64' else ' '.join(x))
Out[1510]:
ID Name COMMENT1 COMMENT2 NUM
0 1 dan hi you hello friend 3.0
1 2 jon dog cat 0.5
2 3 jon yeah yes nope no 3.1
关于 python Pandas : Groupby Sum AND Concatenate Strings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47600818/
在OOCalc中,我想使用CONCATENATE函数为A列中的每个字符串添加引号。 所以在单元格 B1 中我想做: =CONCATENATE("\"",A1,"\"") OOCalc 不喜欢这样,或者
我对此进行了编码,当我运行它时,它向我显示一条消息,变量“Number”与其余串联“大于5”之间的“+”中存在问题 这是代码 fun main(args: Array) { print("En
我正在尝试连接多个 dask 数据帧,但这会导致我的所有 RAM 都用完并使我的环境 (Google Colab) 崩溃。 我曾尝试与 Dask 连接,因为我听说 Dask 会对文件进行分区,以便更容
常规语言在串联下是封闭的 - 这可以通过使一种语言的接受状态以 epsilon 过渡到下一种语言的开始状态来证明。 如果我们考虑语言 L = {a^n | n >=0},这种语言是正则的(就是一个*)
有什么方法可以跨多行使用 | 字符串运算符? 使用经典的 CONCATENATE 标记,您可以进行如下分配: CONCATENATE 'A rubber duck is a toy shaped li
我有一个表单,其中包含许多格式为 name="field-1" name="field-2" name="field-3" name="field-4" 等等.... 在表单操作页面上,我希望能够使用
我们如何连接动态工作区的字段?这个想法在下面的代码中: LOOP AT lt_final INTO DATA(ls_final). CONCATENATE ls_final-field1
我需要将符号从 4 位数字扩展到 32 位数字。 我尝试像这样重复 MSB 28 次: assign x={28'b{a[3]},a[3:0]}; 但是,我得到一个错误: Syntax error n
我的数据如下所示: ColumnName PrimaryKey 1 ID Y 2 JOB_NAME N 3 JOB_DES
我试图用 Perl6 连接一个字符串,因此: my $cmd = "databricks jobs --job-id 37 --notebook-params '\{"; put $cmd; $cmd
我是 verilog 的初学者。 几乎所有的连接示例如下。 wire [3:0] result; reg a, b, c, d; result = {a, b, c, d}; 以下也可以吗? wir
我正在尝试在 VHDL 上实现它: a<=(b+c)/16; 这个我试过了,但是synthesis不接受。 signal b,c : std_logic_vector(7 downto 0); s
我很难理解 Verilog 中的以下语法: input [15:0] a; // 16-bit input output [31:0] result; // 32-bit output a
假设我有一个占位符 ph_input = tf.placeholder(dtype=tf.int32, [无, 1]) 和一个向量 h = tf.zeros([1,2], dtype=tf.int32
假设我有 ceylon 字符串列表。 (不一定是 List ;它可以是可迭代对象、序列、数组等)将所有这些字符串连接成一个字符串的最佳方法是什么? 最佳答案 最有效的解决方案是使用静态方法String
这个问题已经有答案了: Why does Java's concat() method not do anything? (6 个回答) 已关闭 8 年前。 我找到了这段代码 public class
似乎预处理器在连接有符号数字的 token 时添加了一个空格。 我试过这个: #define DECL_FL(IE) 1e##IE##f float val[] = { DECL_FL(12)
我正在实现一个基于作者的图书搜索功能。我应该返回一个查询结果,其中包含查询作者撰写的所有书籍。但是,对某些作者姓名的查询可能会返回多个结果(例如,查询“Smith, W”可能会匹配“Smith, We
我正在尝试将多个单元格添加在一起,并且在它们之间,我需要一个 IF 公式。我基本上是根据我拥有的列表制作 HTML 输出,我需要检查列中是否有“事件”或“终止”,并根据该列表选择要使用的 html 类
通常,当您链接到另一个单元格时,您会返回该单元格的内容。 我想做的是这样的: =HYPERLINK(CONCATENATE("=C:/documents/'[",B15,".xls]Sheet 1'!
我是一名优秀的程序员,十分优秀!