Hot answers tagged

2

The easiest way of achieving this would probably to split the string column using the fraction character and then dividing the first value by the second value: import pandas as pd df = pd.DataFrame({"col": ["250/500", "100/300", "500/1000"]}) df["result"] = df["col"].str.split("/").apply(...


1

You can try using sklearn's MultiLabelBinarizer (https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MultiLabelBinarizer.html): mlb = MultiLabelBinarizer() mlb.fit(d['IDs']) new_col_names = ["ID_%s" % c for c in mlb.classes_] # Create new DataFrame with transformed/one-hot encoded IDs ids = pd.DataFrame(mlb.fit_transform(d['...


1

If I understand what you need, I think it is this: b = a.pivot_table(values='TOTAL_BALANCE_EUR', index=['NSFR_GROUP', 'BALANCE_GROUP'], columns='GAP', aggfunc='sum') b It's easier for others to help you if you make the data available to others. Just make a tiny dataframe with 10 rows for instance. Also, you can make the code a bit easier to read by ...


Only top voted, non community-wiki answers of a minimum length are eligible