1

Have a function to assign a hex color variable based on a scale from 0-1.

In one column I have pageviews that are being assigned a scale:

df1['pvScale'] = df1['GA Page Views']/max(df1['GA Page Views'])

But when I go to create another column and have that be based off a function for assigning hex values:

df1['hex'] = colorscale("#00ff4c", df1['pvScale']) #(orginal hex, 0-1)

Getting this return:

"ValueError: The truth value of a Series is ambiguous."

What's the correct syntax to perform this operation?

1 Answer 1

1

Try using df.apply():

df1['hex'] = df['pvScale'].apply(lambda x: colorscale("#00ff4c", x))

It will apply the colorscale function on the values in one-by-one.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I was trying to use .apply but didn't have the lambda function.

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.