1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Assigning to a subset of a Dataframe (with a selection or other method) in python...

Discussão em 'Python' iniciado por Stack, Setembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    In Pandas I can do the following:

    data = pd.DataFrame(
    {
    "era": ["01", "01", "02", "02", "03", "10"],
    "pred1": [1, 2, 3, 4, 5,6],
    "pred2": [2,4,5,6,7,8],
    "pred3": [3,5,6,8,9,1],
    "something_else": [5,4,3,67,5,4],
    })
    pred_cols = ["pred1", "pred2", "pred3"]
    ERA_COL = "era"
    DOWNSAMPLE_CROSS_VAL = 10

    test_split = ['01', '02', '10']
    test_split_index = data[ERA_COL].isin(test_split)
    downsampled_train_split_index = train_split_index[test_split_index].index[::DOWNSAMPLE_CROSS_VAL]

    data.loc[test_split_index, "pred1"] = somefunction()["another_column"]


    How can I achieve the same in Polars? I tried to do some data.filter(****) = somefunction()["another_column"], but the filter output is not assignable with Polars.

    Continue reading...

Compartilhe esta Página