Update Multiple Column Values with Koalas

92 views Asked by At

In Pandas I can use the following to select rows for 4 dates and then change the each date's value in a second column power_table_2

df.loc[df['date'].isin(['2022-03-14','2022-03-22','2022-04-01','2022-04-05']),'power_table_2'] = ['3/96','14/96','7/96','9/96']

In Koalas, I can successfully do the following:

kdf.loc[kdf['date'].isin(['2022-03-17','2022-03-28','2022-03-29','2022-04-01']),'power_table_2'] = '3/96'

But if I do this

kdf.loc[kdf['date'].isin(['2022-03-17','2022-03-28','2022-03-29','2022-04-01']),'power_table_2'] = ['3/96','14/96','7/96','9/96']

I get this error


java.lang.RuntimeException: Unsupported literal type class java.util.ArrayList [3/96, 14/96, 7/96, 9/96]

How can I update multiple values in Koalas like in Pandas?

Thanks

1

There are 1 answers

0
G.G On

use update

kdf.loc[kdf['id'].isin(['1','2','3']),'A'].update(ps.Series([1,2,3]))
kdf

out:

  id    A    B     C  D
0   1  1.0  2.0  99.0  0
1   2  1.0  4.0   NaN  1
2   3  1.0  NaN   NaN  5
3   4  NaN  3.0   1.0  4