Categories
Mastering Development

SQL check if group is continuous when ordered and return broken groups

I am trying to find a way to list rows, that are breaking continuous groups of records. I say groups, because we could use GROUP BY to list values of groups (but that is not applied, we need particular rows). Sample data: CREATE TABLE Test (ID INT, NNO INT, DIDX INT, SIDX INT); — Valid […]

Categories
Mastering Development

Substitute in column of dataframe if the integer values meet certain criteria [duplicate]

Instead of having Age in numbers, I need to group them by certain age groups that get substituted on the data frame import pandas as pd # intialise data of lists. data = {‘Name’:[‘Tom’, ‘nick’, ‘krish’, ‘jack’,’Ann’,’James’], ‘Age’:[20, 21, 45, 58,34,60]} # Create DataFrame df = pd.DataFrame(data) This is what I tried: if df[‘Age’] < […]

Categories
Mastering Development

How to Un-Sort The legends in the graph in R?

I am not an expert in R. I am having an issue, the legends are sorted alphabetically. I cannot arrange them manually because I have 87 patients and each patient has 300 days and the status (category) changes every day so i want to plot the graph exactly like it has in the source. ggplot(data […]

Categories
Mastering Development System & Network

How to Convert Arrays in SQL to Int

Can someone let me know how to convert/replace/remove array datatypes from my tables into Integers. I am trying to convert/replace the Arrays in columns, Monday, Tuesday, Wednesday, Thursday, Friday to integers I have used the following code on the Friday field: SELECT CONVERT(INT, consumersearchtest.Friday) AS FridayFROM dbo.consumersearchtest But I get the following error: 1 Conversion […]

Categories
Mastering Development

ggplot2 How to put at bottom the x axis title?

I have this dataframe: Control Stress days sd_control sd_stress X1 -0.2866667 -0.2833333 X1 0.11846237 0.05773503 X2 -0.2566667 -1.0333333 X2 0.08144528 0.15275252 X3 -0.4766667 -1.4500000 X3 0.09291573 0.10000000 X4 -0.4900000 -1.2766667 X4 0.21517435 0.22501852 X5 -0.4600000 -1.2666667 X5 0.07549834 0.40722639 X6 -0.2633333 -1.0833333 X6 0.12662280 0.10408330 X7 -0.2833333 -1.0333333 X7 0.03511885 0.07767453 Based on this data […]

Categories
Mastering Development

cannot arrange numbers into shape (n,n) matrix

I have the following code that generates a fractal image, the problem is how to reconstruct numbers to be a matrix. from PIL import Image from pylab import * from numpy import NaN import numpy as np import matplotlib.pyplot as plt def julia(C): X = arange(-1.5, 1.5, 0.05) Y = arange(-1.5, 1.5, 0.05) pixel = […]

Categories
Mastering Development

Search and process data from multi-index DataFrames

I have two dataframes df2, with the payment statistics (that have the probability of the client pay a certain debt) and df3 with new clients data. import pandas as pd d = {‘City’: [‘Tokyo’,’Tokyo’,’Lisbon’,’Tokyo’,’Tokyo’,’Lisbon’,’Lisbon’,’Lisbon’,’Tokyo’,’Lisbon’,’Tokyo’,’Tokyo’,’Tokyo’,’Lisbon’,’Tokyo’,’Tokyo’,’Lisbon’,’Lisbon’,’Lisbon’,’Tokyo’,’Lisbon’,’Tokyo’], ‘Card’: [‘Visa’,’Visa’,’Master Card’,’Master Card’,’Visa’,’Master Card’,’Visa’,’Visa’,’Master Card’,’Visa’,’Master Card’,’Visa’,’Visa’,’Master Card’,’Master Card’,’Visa’,’Master Card’,’Visa’,’Visa’,’Master Card’,’Visa’,’Master Card’], ‘Colateral’:[‘Yes’,’No’,’Yes’,’No’,’No’,’No’,’No’,’Yes’,’Yes’,’No’,’Yes’,’Yes’,’No’,’Yes’,’No’,’No’,’No’,’Yes’,’Yes’,’No’,’No’,’No’], ‘Client Number’:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22], ‘DebtPaid’:[0.8,0.1,0.5,0.30,0,0.2,0.4,1,0.60,1,0.5,0.2,0,0.3,0,0,0.2,0,0.1,0.70,0.5,0.1]} df = pd.DataFrame(data=d) df2=df.groupby([‘City’,’Card’,’Colateral’])[‘DebtPaid’].\ value_counts(bins=[-0.001,0,0.25,0.5,0.75,1,1.001,2],normalize=True) […]

Categories
Mastering Development

Fit Variance gamma to data

I am using R studio to estimate paramters for data under Variance Gamma. I want to fit this data to the data and find estimates of parameters. The code I have is x<-c(1291,849,238,140,118,108,87,70,63,58,50,47,21,21,19) library(VarianceGamma) init<-c(0,0.5,0,0.5) vgFit(x, freq = NULL, breaks = NULL, paramStart = init, startMethod = "Nelder-Mead", startValues = "SL", method = "Nelder-Mead", hessian […]

Categories
Mastering Development

How to remove outliers from multiple columns in pyspark using mean and standard deviation

I have the below data frame and I want to remove outliers from defined columns. In the below example price and income. Outliers should be removed for each group of data. In this example its ‘cd’ and ‘segment’ columns. Outliers should be removed based 5 standard deviations. data = [ (‘a’, ‘1’,20,10), (‘a’, ‘1’,30,16), (‘a’, […]

Categories
Mastering Development

how to calculate the scatter within classes for a 50×20 matrix

I am trying to reduce a largely dimentional matrix to only 2D, i was using an example for 2D arrays,which works, but i would need to do the same for a higher dimentional scatter. I have two classes and each classes have matrices of 50×20 dimensional feature spaces. For my example i have these 2D […]