我想对具有相同名称开头的列进行求和。
例子 :
import pandas as pd
import numpy as np
df=pd.DataFrame({'product':['TV','COMPUTER','SMARTPHONE'],
'price_2012':np.random.randint(100,300,3),
'price_2013':np.random.randint(100,300,3),
'price_2014':np.random.randint(100,300,3),
'price_2015':np.random.randint(100,300,3),
'price_2016':np.random.randint(100,300,3)})
Run Code Online (Sandbox Code Playgroud)
对于这个例子,我想创建一个新列price_2012_2016,等于2013年到2016年的价格总和,而不列出所有列。
PS:在SAS中我喜欢这样:price_2012_2016=sum(of prix_2012-prix-2016);
诚挚的,劳伦特 A.
我通过网址发送带有net/http包的Json数据,我想要一些小写的键作为回报,但它不起作用.
在这个问题的例子中,我想要小写的'count'和'data'键.
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type tableau struct {
Count int `json"count"`
Data []People `json"data"`
}
type People struct {
Id int `json"Id"`
Name string `json"Name"`
Age int `json"Age"`
}
func main() {
http.HandleFunc("/people", recupPeople)
fs := http.FileServer(http.Dir("Static"))
http.Handle("/", fs)
http.ListenAndServe(":80", nil)
}
func recupPeople(w http.ResponseWriter, r *http.Request) {
listPeople := &tableau{
Count: 4,
Data: []People{
People{Id: 1, Name: "Laurent", Age: 20},
People{Id: 2, Name: "Laurent", Age: 20},
},
}
peop, _ := json.Marshal(listPeople)
fmt.Println(string(peop)) …Run Code Online (Sandbox Code Playgroud)