Categories
Mastering Development

Split dataframe with all values in one row

I got the following dataframe which is created dynamically but saves all the relevant values into one row: df +—————-+—————-+—————-+—————-+ | 1 | 2 | 3 | 4 | +—————-+—————-+—————-+—————-+ | a1, b1, c1, d1 | a2, b2, c2, d2 | a3, b3, c3, d3 | a4, b4, c4, d4 | +—————-+—————-+—————-+—————-+ I need to […]

Categories
Mastering Development

minimization Converging to negative infinity despite constraints

I have the following optimization problem: from scipy import optimize import numpy as np def net_profit(x): return -(x[0] / (x[1] + x[2] + x[3]) * 365 * \ (x[4] – (x[5] + x[6])) * x[7] + \ x[8] * 12 – x[9] * 12) c0 = {‘type’: ‘ineq’, ‘fun’: lambda x: x[0]} c1 = {‘type’: […]

Categories
Mastering Development

Overlapping text on top of geom_bar in ggplot2

I have made a barplot similar to the one below using ggplot2. I cannot get the percentages on top of the bars to be centered and not overlapping of other bars and numbers. Sample code is below. library(tidyverse) cat1=c("cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1", "cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2", "cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3", "cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4") cat2=c("c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12") count1=round(rnorm(48,10)) fakeperc=rnorm(48,9) df1=cbind(count1,fakeperc) df2=cbind(cat1,cat2) finaldf=as.data.frame(cbind(df1,df2)) finaldf$cat1=as.factor(finaldf$cat1) finaldf$fakeperc=as.numeric(finaldf$fakeperc) #finaldf$cat1=factor(finaldf$cat1,levels = […]

Categories
Mastering Development

Flatten nested object/array in javascript

I’m new to Javascript and I have nested objects and arrays that I would like to flatten. I have… [{ a: 2, b: [{ c: 3, d: [{e: 4, f: 5}, {e: 5,f: 6}]}, { c: 4, d: [{e: 7, f: 8}]} ] }] and would like… [{a:2,c:3,e:4,f:5}, {a:2,c:3,e:5,f:6}, {a:2,c:4,e:7,f:8}] I’ve tried to adapt the […]

Categories
Mastering Development

Flatten nested array in javascript

I have a nested array that I would like to flatten. I have… [{ a: 2, b: [{ c: 3, d: [ { e: 4, f: 5 }, { e: 5, f: 6 } ] c:4, d: [ { e:7, f:8 } ] }] }] and would like… [ {a:2,c:3,e:4,f:5}, {a:2,c:3,e:5,f:6}, {a:2,c:4,e:7,f:8} ] I’ve tried […]

Categories
User Help Web Apps

Google Sheets look for string in area

I have in my sheet a list of names in every second line (A2, B2, C2, D2, A4, B4, C4, D4, A6, and so on) and those names can appear in 1 of 4 areas(e.g. H3:I13 or K3:L13) in the same sheet. Now I want to change the background color of the names in the […]

Categories
User Help Web Apps

Google Sheets look for string in area

I have in my sheet a list of names in every second line (A2, B2, C2, D2, A4, B4, C4, D4, A6, and so on) and those names can appear in 1 of 4 areas(e.g. H3:I13 or K3:L13) in the same sheet. Now i want to change the background color of the names in the […]

Categories
Mastering Development

Javascript – compare two arrays with filter as efficient as possible

I want to compare two arrays with filter as efficiently as possible, and also as descriptively as possible. I am sure there must be a nice way to do this without resorting to forEach, but for the life of me I cannot find it, would anyone be kind enough to help me out of my […]

Categories
Mastering Development

Create NetowrkX Graph from Pandas DataFrame

Im trying to create a graph from this data structure, where U are the nodes and C are the relations between the nodes U. Right now I have the following structure df = pd.DataFrame({‘C’: [‘C1’, ‘C2’, ‘C3’, ‘C4’], ‘U1’: [1,0,1,0], ‘U2’: [1,0,0,0], ‘U3’: [0,1,1,0], ‘U4’: [1,0,0,0], ‘U5’: [0,1,0,1]}) C U1 U2 U3 U4 U5 0 […]

Categories
Mastering Development

How to stop the influence of other people being simultaneously on a website?

I do a Django survey and everything runs fine if only one person at a time answers it. In one of my functions (when loading one URL), there is a randomizer who randomizes the order of a list. However, if another person answers the survey and opens the url, the randomizer stars working and randomizes […]