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

Pandas: dynamically append dataframe column into a running total dataframe within a loop

I am writing a simulation and I am trying to append the result of EACH ITERATION INTO a dataframe that keep track of all the iterations. While everything works fine with collecting the results, I cannot find a way to append the results into a new column each time. I have been banging my head […]

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
Database Development

Optimal selection of predefined non-materialised data

Take the following result set as an example: Store Category Item Cost Stock Sold Ordered ABC Accessories Lock 344.31 281 141 225 DEF Components Chain 24.15 312 53 45 GHI Other Gloves 57.50 121 102 100 … We are looking to demo a feature for our application and this requires us to pull data in […]

Categories
Mastering Development

I want to search for data when I select multi-user and multi-project using laravel?

I am trying to search for data when I select multi-user and multi-project then I click on the search button but unfortunately, data is not showing on the report please help me how to do that thanks. return $request { "_token": "Y293JntHDWb40vqe5hG80ebhoxsxAGaWA00DcAkn", "user": [ "3", "4", "8" "project": [ "43", "44", "45", "46" ], "date": […]

Categories
Mastering Development

How to organize 2 level array to a custom dictionary format?

I’m trying to convert this array a = [ [‘A’,’B’,’C’], [1,33,45], [721,22,9] ] to a dictionary in order to have this output: b = { ‘A’:[1,721], ‘B’:[33,22], ‘C’:[45,9] } My current code is like this, getting this error: b = {} for i in range(1,len(a)): for j in range(len(a[i])): b[a[0][j]].append(a[i][j]) Traceback (most recent call last): […]

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
Game Creation Mastering Development

How to calculate FOV angle range based on facing and mouse aim position

The title is not that clear so I’ll explain. In my top down shooter game the player can be faced in any of the 8 directions using the keyboard. Then depending on the direction he will have a 90 degree field of view to turn based on the angle selected by mouse position. Obviously the […]

Categories
Mastering Development

Python: Reading and obtaining certain parts of a text file

I have a text file that has coordinates in a format of [x1, y1, x2, y2]. How would I be able to obtain just the y1 and y2 coordinates? Example: [23, 45, 90, 79] Obtain 45 and 79