在阅读这篇文章时,我看到了这样的说法。
order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index()
Run Code Online (Sandbox Code Playgroud)
除了reset_index()方法调用之外,其他一切我都清楚。我的问题是,如果我不reset_index()考虑以下给定的顺序打电话,会发生什么?
order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index()
df_1 = df.merge(order_total)
df_1["Percent_of_Order"] = df_1["ext price"] / df_1["Order_Total"]
Run Code Online (Sandbox Code Playgroud)
我试图从https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.reset_index.html了解此方法,但无法理解重置索引是什么意思一个数据框。
在下面的适配器设计模式示例代码中,为什么要引入新类而不是在客户端中使用多个接口?
interface ITarget
{
List<string> GetProducts();
}
public class VendorAdaptee
{
public List<string> GetListOfProducts()
{
List<string> products = new List<string>();
products.Add("Gaming Consoles");
products.Add("Television");
products.Add("Books");
products.Add("Musical Instruments");
return products;
}
}
class VendorAdapter:ITarget
{
public List<string> GetProducts()
{
VendorAdaptee adaptee = new VendorAdaptee();
return adaptee.GetListOfProducts();
}
}
class ShoppingPortalClient
{
static void Main(string[] args)
{
ITarget adapter = new VendorAdapter();
foreach (string product in adapter.GetProducts())
{
Console.WriteLine(product);
}
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下与上述代码相关的查询.
给定N 个64 位无符号整数,我希望将它们有效地存储在数据结构D中,并能够执行以下查询:
给定一个整数A,返回D中至少k 个最高有效位相同的所有整数。
例如,如果有一个包含 3 个 64 位整数的列表:
a. 1010010000000000010000000000000000000000100000000000000000000001
b. 0000000100001000000000010000000000000000000000000000000000000001
c. 1010010100000000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
查询A是:
1010010000000000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
我们选择 k = 7
它应该返回一个包含 2 个元素的列表:
a.1010010000000000010000000000000000000000100000000000000000000001
c.1010010100000000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
如果查询 A1 是:
0010010000000000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
k = 2
它应该返回一个包含一个元素的列表:
b. 0000000100001000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
如果查询 A2 是:
1110010000000000000000010000000000000000000000000000000000000001
Run Code Online (Sandbox Code Playgroud)
k = 3
它应该返回一个空列表。
N 的大小应为 5000 万个整数的量级。
你能指出最合适的数据结构吗?另外,如果我可以在创建数据结构 D 后对其进行插入/删除,那就太好了。
这该怎么做:
#include <tuple>
std::tuple<double, int[2]> f()
{
return std::make_tuple(0., {1, 2});
}
int main()
{
f();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
无法将“std::make_tuple<{}>()”从“std::tuple<>”转换为“std::tuple”
编译器不知道该怎么做吗?
代码正在打印所有构造函数.我读到当我们从另一个类派生一个类时,构造函数不会被继承.那么为什么创建c是从b和调用构造函数a
class A
{
public:
A() { cout << "A's constructor called" << endl; }
};
class B
{
public:
B() { cout << "B's constructor called" << endl; }
};
class C: public B, public A // Note the order
{
public:
C() { cout << "C's constructor called" << endl; }
};
int main()
{
C c;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 几周前我在一个分支机构工作,但我不记得分支机构的名称(有很多).我希望能够做到这样的事情:
git branch --print-last-commit
并输出如下内容:
branch 1 - 2017-02-12
branch 2 - 2016-12-30
Run Code Online (Sandbox Code Playgroud)
等等
有没有办法做到这一点?
我需要使用3"for"循环输出来编写一些java
122333444455555
22333444455555
333444455555
444455555
55555
我到目前为止的代码:
public static void problemFour() {
for(int i = 5; i >= 1; i--) {
for(int a = 1; a <= i; a++) {
for(int b = 1; b <= a; b++) {
System.out.print(a);
}
}
System.out.println();
}
}
Run Code Online (Sandbox Code Playgroud)
这输出
111112222333445
11111222233344
111112222333
111112222
11111
Run Code Online (Sandbox Code Playgroud)
我已经转换了很多++的's,'s,>',5和1的组合.
我很困惑,如果有人能指出我正确的方向,那就太棒了.
对于这个字符串dirPath,
String dirPath = "c:/create/a/dir/very/deep/inside/../././../../../dir/";
Run Code Online (Sandbox Code Playgroud)
我希望输出字符串看起来像:
"c:/create/a/dir/very/deep/inside/../../../../dir/";
Run Code Online (Sandbox Code Playgroud)
我用了 :
dirPath.replaceAll("/[.]/", "/");
Run Code Online (Sandbox Code Playgroud)
但那给了:
c:/create/a/dir/very/deep/inside/.././../../../dir/
^^^
Run Code Online (Sandbox Code Playgroud)
然后,再试一次replaceAll:
dirPath.replaceAll("/[.]/", "/").replaceAll("/[.]/", "/");
Run Code Online (Sandbox Code Playgroud)
那工作!
我的问题是为什么一个电话无法达到相同的结果?如何以最简单的方式实现它?
PS另一个对我不起作用的正则表达式: .replaceAll("($|/)[.]/", "$1")
我有一个字符串列表def123,abc999,zzz000,abc123,zzz111.我希望列表排序,使前三个字符按升序排序,接下来三个按降序排序.所以输出应该是abc999,abc123,def123,zzz111,zzz000 这可能吗?
您如何证明具有n个节点的二进制堆恰好具有⌈n/2⌉个叶节点?