How to group by one column or another in pandas

I have a table like: col1 col2 0 1 a 1 2 b 2 2 c 3 3 c 4 4 d I’d like rows to be grouped together if they have a matching value in col1 or col2. That is, I’d like something like this: > ( df .groupby(set(‘col1’, ‘col2’)) # Made-up syntax .ngroup())… Read More How to group by one column or another in pandas

Type-inference for switch-case block with dynamic case strings

A tricky TS challenge. Say one has two objects with a type property, and a specific property, fooData or foo2Data, that is specific to the type value of the object. For example: const dynamicString: string = ‘abc’ const fooTypeName = `foo${dynamicString}` as const // const fooTypeName: `foo${string}` const foo2TypeName = `foo${dynamicString}2` as const // const… Read More Type-inference for switch-case block with dynamic case strings

Why some commands cause an error relative to the preceding command?

This is a pandas question. Try to copy this in Jupyter Notebook: In [1]: df = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=[‘cobra’, ‘viper’, ‘sidewinder’], columns=[‘max_speed’, ‘shield’]) df In [2]: df.pop(‘shield’) # Return as series. In [3]: pd.DataFrame(df.pop(‘shield’)) # Return as DataFrame. Then inverse it to the sequence of In[1] In[3] In[2] Why the 3rd… Read More Why some commands cause an error relative to the preceding command?