# Filter dataframe using multiple values

Advertisements As the title says, I have a dataframe and I want to filter (keep) rows where the id variable is either 1 or 2. An example: using DataFrames # eaxample data set df1 = DataFrame(id = repeat(1:3, 3), name = repeat(["bob", "jane", "steve"], inner = 3)) # filtering based on a single id -… Read More Filter dataframe using multiple values

# Delete certain rows of a matrix in julia

Advertisements I am learning julia in a university course and I have to do an assigment but I don’t know how to preprocess the data. Hi have a matrix with patterns distributed in rows. Its dimension is 1521×4. The first attribute take values from 0 to 4 and I want to delete patterns (rows) whose… Read More Delete certain rows of a matrix in julia

# what does numpy.vectorize(lambda x:1 – x^3) do?

Advertisements I’m new to python and also to numpy package. I was wondering what does this specific line really do. a = numpy.vectorize(lambda x:1 – x^3) I’ve searched about vectorize function but didn’t really get what it does. I’m familiar with julia if there is any instance in julia that does what this line does… Read More what does numpy.vectorize(lambda x:1 – x^3) do?

# How do I graph a line in Julia with an arrow on both sides?

Advertisements Here is my code: using MTH229 using Plots f(x)=x theme(:dark) plot(f,-5,5,linewidth=5,c=:hotpink,legend=false,arrow=true) Here is a picture of the output: plot How do I get the arrow to appear on both ends of the line instead of just one? >Solution : It’s a bit of a hacky solution, but for the example in the question: plot!([-4.99,-5],[f(-4.99),… Read More How do I graph a line in Julia with an arrow on both sides?

# How can I sum arrays row-wise in Julia?

Advertisements Suppose that I have a 2×2 array of the form: [a, b c, d] Here a, b, c and d are numbers. How can I calculate the column-wise sum in Julia? The result should be the column vector: [a + b c + d]. >Solution : Assume your data is mat = [11 12;… Read More How can I sum arrays row-wise in Julia?

# How to purge missing values from a DataFrame in Julia?

Advertisements After reading the context, if you felt the title could be enhanced to fit the question and you had an idea, feel free to update it. Suppose I have the following DataFrame: using DataFrames df = DataFrame( g=["a","b","a","c",missing,missing,missing,missing], a=[1,2,3,4,missing,missing,missing,missing], Column1=[missing,missing,missing,missing,false,false,false,true], Column2=[missing,missing,missing,missing,false,true,true,true], Column3=[missing,missing,missing,missing,true,true,false,false], ) # 8×5 DataFrame # Row │ g a Column1 Column2 Column3… Read More How to purge missing values from a DataFrame in Julia?

# Julia: How to make a matrix in for loop

Advertisements I’m a newbie to Julia. Before then, I used Matlab. For the Matlab case, I wrote commands to make the matrix in the for loop, as follows: for i=1:1:100; k(i,:)=i.^2; end I typed the same commands in Julia, but it didn’t work. Furthermore, I tried other commands as follows: n=100; k = Array{Int64, n};… Read More Julia: How to make a matrix in for loop

# "ERROR: ArgumentError: Table returned but a single output column was expected" in transform! dataframes

Advertisements I want to perform a simple One-Hot encoding by utilizing DataFrames.jl‘s transform! but I’m unsuccessful. I use the following DataFrame: using DataFrames df = DataFrame( color = ["red", "green", "blue"], x = [1, 2, 3] ) # 3×2 DataFrame # Row │ color x # │ String Int64 # ─────┼─────────────── # 1 │ red… Read More "ERROR: ArgumentError: Table returned but a single output column was expected" in transform! dataframes

# Julia dictionaries

Advertisements Is there a function to get a list of all the dictionaries I am using in a Julia session? I am trying to find the value of a key inside a dictionary, but cant seem to find the dictionary and wanted to make sure I have it. >Solution : I assume that you want… Read More Julia dictionaries

# Index array with vector of tuples

Advertisements I have a vector of tuples, where each tuple represents a position in a 2d array. I also have a 2d array of values For example: # create a vector of tuples tupl1 = ((1,1), (2,3), (1,2), (3,1)) # create a 2d array of values m1 = zeros(Int, (3,3)) m1[1:4] .= 1 I want… Read More Index array with vector of tuples