小编ale*_*oon的帖子

在pandas中设置多列索引

我像这样制作数据帧.

df = pd.DataFrame({
    'class' : ['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'],
    'number' : [1,2,3,4,5,1,2,3,4,5],
    'math' : [90, 20, 50, 30, 57, 67, 89, 79, 45, 23],
    'english' : [40, 21, 68, 89, 90, 87, 89, 54, 21, 23]
})
Run Code Online (Sandbox Code Playgroud)

我想通过使用一些pandas方法将索引转换为此.(例如set_index,stack ,,,)

df1 = pd.DataFrame(np.random.randint(1, 100, (5, 4)),
             columns = [['A', 'A', 'B', 'B'],['english', 'math', 'english', 'math']],
             index = [1, 2, 3, 4, 5])
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python numpy pandas

11
推荐指数
2
解决办法
2万
查看次数

Golang - 如何将结构添加到切片并保留内存地址?

如下所示,我创建实例并添加到切片。我想保留实例的内存地址,但事实并非如此。

type Person struct {
    name string
}

func main() {
    p := Person{name: "foo"}
    ps1 := []Person{p}
    ps2 := []Person{p}
    
    fmt.Printf("%p\n", &p) // 0xc000010250
    fmt.Printf("%p\n", &ps1[0]) // 0xc000010260
    fmt.Printf("%p\n", &ps2[0]) // 0xc000010270
}
Run Code Online (Sandbox Code Playgroud)

我知道如果我使用指针和指针切片是可能的。

type Person struct {
    name string
}

func main() {
    p := Person{name: "foo"}
    ps1 := []*Person{&p}
    ps2 := []*Person{&p}

    fmt.Printf("%p\n", &p) // 0xc00010a210
    fmt.Printf("%p\n", ps1[0]) // 0xc00010a210
    fmt.Printf("%p\n", ps2[0]) // 0xc00010a210
}
Run Code Online (Sandbox Code Playgroud)

但是,我想将 ps1 和 ps2 设置为 []Person 类型,因为后面的方法的参数类型(不在此处)。有什么办法吗?

go

-3
推荐指数
1
解决办法
212
查看次数

标签 统计

go ×1

numpy ×1

pandas ×1

python ×1