data-wrangling

How to count occurrences per label?

How to count occurrences per label? Question: How can I count the 1’s and 0’s in column [1] per unique class in column [0]? labels = [] estimator = est.fit(X.iloc[:,1:]) labels.append(estimator.labels_) labels.append(O) labels = pd.DataFrame(np.array(labels).transpose()) labels.iloc[:,1] = (labels.iloc[:,1] > 5).astype(int) # Binary GOS-E x = np.array(labels.iloc[:,1]).reshape(-1, 1) y = np.array(labels.iloc[:,0]) Asked By: Sean_TBI_Research || Source …

Total answers: 1

How to append entire rows based on matching conditions in a pandas dataframe?

How to append entire rows based on matching conditions in a pandas dataframe? Question: I have a dataframe which looks like the: import pandas as pd df_ref = pd.DataFrame({‘district’:[‘A Nzo DM’,’A Nzo DM’,’uMgungundlovu DM’,’uMgungundlovu DM’,’uMgungundlovu DM’,’uMgungundlovu DM’,’uMgungundlovu DM’], ‘visit_date’:[‘2021-07-31′,’2021-07-31′,’2021-07-31′,’2021-07-31′,’2021-08-31′,’2021-08-31′,’2021-08-31’], ‘province’:[‘EC’,’EC’,’NC’,’NC’,’NC’,’NC’,’NC’], ‘age_group’:[’35-49′,’50-59′,’18-34′,’35-49′,’18-34′,’35-49′,’Unidentified’], ‘sex’:[‘Male’,’Female’,’Female’,’Male’,’Female’,’Male’,’Female’], ‘vaccinations’:[1,5,6,8,9,10,14]}) The data is going to be used in data visualization software I …

Total answers: 1

Python build dict from a mixture of dict keys and list values

Python build dict from a mixture of dict keys and list values Question: Input body is: {‘columns’: [‘site_ref’, ‘site_name’, ‘region’], ‘data’: [[‘R005000003192’, ‘AIRTH DSR NS896876’, ‘WEST’], [‘R005000003195’, ‘AIRTHREY DSR NS814971’, ‘WEST’]]} How could I build a new dict that will take the column values as keys and then populate a new dict for every list …

Total answers: 1

Good alternative to Pandas .append() method, now that it is being deprecated?

Good alternative to Pandas .append() method, now that it is being deprecated? Question: I use the following method a lot to append a single row to a dataframe. One thing I really like about it is that it allows you to append a simple dict object. For example: # Creating an empty dataframe df = …

Total answers: 8