1

i have a color dataframe with 4 columns and an array of [3,]

index = ["color","R", "G", "B"] # index as csv file definition
colors_csv = read_csv(csv_path , names=index, header=None)
colors = [[159 147 134][252 252 252][ 75  81  75][229 195 184]] # sample RGB data

i want to get a new sub dataframe from colors_csv with all the occurrence of colors in R,G,B columns

by far using .loc property will return me a correct list but consist of concatenated item which i can't iterate through and acquire new dataframe

# query with array of colors 
for i in range(len(colors)):
    aaaa = ([colors_csv.loc[(colors_csv['R'] == colors[i][0]) & 
        (colors_csv['G'] == colors[i][1]) & (colors_csv['B'] == colors[i][2])]])
    print(aaaa) # how to have all these aaaa thorough loop as one dataframe 

and i guess there could be a one line magic code which can do the job :)

any help appreciated

1 Answer 1

2

Use merge with default merge by all columns with DataFrame created from RGB data:

colors_csv = read_csv(csv_path , names=index, header=None)

out = colors_csv.merge(pd.DataFrame(colors, columns=["R", "G", "B"]))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.