在xarray数据集中组合DataArrays

时间:2017-12-11 21:06:38

标签: python python-xarray

对于xarray数据集中的所有DataArrays有没有比

更好的求和方法
ds.sum()

这有效,但看起来有点笨重。是否有相当于对pandas DataFrame列进行求和?

注意// get locally stored recipe values var local_recipes=localStorage.getItem("recipes"); // check if recipes is defined in local storage if(typeof local_recipes !== 'undefined' && local_recipes !== null){ // if recipe is stored in local storage var local_recipes=JSON.parse(localStorage.getItem("recipes")) }else{ // if recipe is not stored in local storage var default_recipes=[ { name: "Pumpkin Pie", ingredients: [ "Pumpkin Puree", "Sweetened Condensed Milk", "Eggs", "Pumpkin Pie Spice", "Pie Crust" ] }, { name: "Spaghetti", ingredients: ["Noodles", "Tomato Sauce", "(Optional) Meatballs"] }, { name: "Onion Pie", ingredients: ["Onion", "Pie Crust", "Sounds Yummy right?"] } ] localStorage.setItem("recipes",JSON.stringify(default_recipes) ); local_recipes=default_recipes } 方法适用于每个DataArrays - 但我想组合DataArrays。

1 个答案:

答案 0 :(得分:3)

我假设你想要对每个数据变量求和,例如sum(d.sum() for d in ds.data_vars.values())。在xarray的未来版本中(尚未在v0.10中),这将更简洁:您将能够编写sum(d.sum() for d in ds.values())

另一种选择是将数据集转换为单个DataArray并立即对其求和,例如ds.to_array().sum()。如果您有不同尺寸的数据变量,效率会降低。

相关问题