EN VI
Posts (0)
Questions (50)
2024-03-13 01:30:05
With (~)isin/explode: pos["flag"] = ~pos.index.isin(pos["id"].explode()) # .astype(int) ? Output : id pred flag 1 [4, 4] NaN True 2 [2] NaN False 3 [2, 4] NaN True 4 [2] N...
Tags: python pandas
2024-03-13 03:30:05
Try: df['max_range'] = df['A'].rolling(4).max() Output: A max_range 0 10 NaN 1 12 NaN 2 14 NaN 3 8 14.0 4 9 14.0 5 10 14.0 6...
2024-03-13 03:30:07
You can drop the second level index and then reset the index: print(df2.droplevel(1).reset_index()) Prints: old_code new_code 0 00000001 99999991 1 00000002 99999992 2 00000002 99999922 3...
Tags: python python-3.x pandas
2024-03-13 04:30:04
IIUC, explode, merge, and concat: out = (pd.concat([ df, legend .explode('word_lists') .rename(columns={'word_lists': 'word'}) .merge(df[['object', 'personID']].d...
Tags: python pandas dataframe
2024-03-13 06:00:07
IIUC you can do left merge on d2: d2 = d2.merge(d1, on=["c1", "c2"], how="left") d2["c1_c2_found"] = d2.pop("val").notna().astype(int) print(d2) Prints: c1 c2 c1_found c2_found c1_c2_found 0 A...
Tags: python python-3.x pandas
2024-03-13 16:00:05
If you want to sample N rows with about the same probability to sample each group, you could oversample per group then sample again: import math N = 4 out = (df.groupby('ID').sample(n=math.ceil(N/df...
Tags: python pandas group-by
2024-03-13 17:00:04
You have to create a Series with the correct index: m = df['B']==4 df.loc[m, 'A'] = pd.Series([np.array([5, 6, 7, 8]), np.array([2, 3])], index=df.index[m]) Note that in a...
Tags: python arrays pandas
2024-03-13 21:30:05
IIUC, you can create a dictionary of indices that are referenced by other indices. Then loop over the -1 indices in reverse and index the relevant rows to pass to f: s = df['pred'].explode() dic = s.i...
Tags: python pandas dataframe
2024-03-14 00:30:08
First check whether the elements you want to select are contained in response / soup; the ones you are addressing do not appear to be present. So as mentioned by @John Gordon your selection is not fin...
Tags: python pandas dataframe
2024-03-14 04:00:05
If the groups are sorted and the pattern is always the same (no missing values), then reshape with numpy: cols = ['Person', 'Place', 'Thing'] out = df.loc[::len(cols), ['Sample']].reset_index(drop=Tr...
Tags: python pandas

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login