How to delete the columns of a dataframe that have only positive values?

I’m trying to edit a DataFrame, my objective is to keep the columns in which at least one value is <=0.

For example, using the code

using DataFrames

data = Dict("A"=>[1,7,2], 
    "B"=>[3,-9,-3], 
    "C"=>[3,0,6], 
    "D"=>[8,4,2], 
    "E"=>[4,3,-4])

df = DataFrame(data)

I get the following result

df1

And I’m trying to transform it into the following DataFrame

df2

There are some options to remove rows based on conditions, but I haven’t found any that does the same to columns.

Does anyone know how to do this in a simple way?

I have answered on StackOverflow here:

https://stackoverflow.com/questions/68675457/how-to-delete-the-columns-of-a-dataframe-that-have-only-positive-values-in-julia

2 Likes