How to create new columns and apply a function #5047
Unanswered
thomashirtz
asked this question in
Q&A
Replies: 1 comment 4 replies
-
I would think of this operation as a concatentation. See https://xarray.pydata.org/en/stable/combining.html#concatenate import numpy as np
import xarray as xr
dataset = xr.Dataset(
{"measurements": (("simulation", "characteristic", "value"), np.random.random((10,3,6)))},
coords={"characteristic": ['a', 'b', 'c']})
logged = np.log(dataset[["measurements"]].sel(characteristic=["b", "c"]))
logged = logged.assign_coords(characteristic=["log_b", "log_c"])
xr.concat([dataset, logged], dim="characteristic")
Do you have suggestions for improving our documentation on this point? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a dataset containing many different coord and data. I would like to take one of the dimension and apply a function to it.
For example:
I would like to select columns, for example
b
andc
, and create a new column so that:(I know that for example, with pandas, I can do something like
df['log_b'] = np.log(df['b'])
)I can easily "create" a new log dataset using :
but after I am not sure how to merge everything while keeping the rest of my dataset
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions