Skip to main content
edited title
Link
Karl Knechtel
  • 61.1k
  • 13
  • 118
  • 165

How do I create a new column where the values are selected based on an existing columnscolumn?

Better title. Simplify formatting.
Source Link
wjandrea
  • 31.6k
  • 9
  • 67
  • 88

Pandas conditional creation of How do I create a series/dataframenew column where the values are selected based on existing columns?

How do I add a color column to the following dataframe so that color='green' if Set   ==   'Z', and color='red' otherwise?

    Type       Set
1    A      A    Z
2    B      B    Z           
3    B      B    X
4    C      C    Y

Pandas conditional creation of a series/dataframe column

How do I add a color column to the following dataframe so that color='green' if Set  ==  'Z', and color='red' otherwise?

    Type       Set
1    A          Z
2    B          Z           
3    B          X
4    C          Y

How do I create a new column where the values are selected based on existing columns?

How do I add a color column to the following dataframe so that color='green' if Set == 'Z', and color='red' otherwise?

   Type  Set
1     A    Z
2     B    Z           
3     B    X
4     C    Y
Post Reopened by wjandrea python
Post Closed as "Duplicate" by Karl Knechtel python
Rollback to Revision 6 - Edit approval overridden by post owner or moderator
Source Link
Dharman
  • 32.6k
  • 25
  • 94
  • 140

How do I add a color column to the following dataframe so that color='green' if Set == 'Z', and color='red' otherwise?

    Type       Set
1    A          Z
2    B          Z           
3    B          X
4    C          Y
df = {'Type': ['A', 'B', 'B', 'C'], 'Set': ['Z', 'Z', 'X', 'Y']}

How do I add a color column to the following dataframe so that color='green' if Set == 'Z', and color='red' otherwise?

    Type       Set
1    A          Z
2    B          Z           
3    B          X
4    C          Y
df = {'Type': ['A', 'B', 'B', 'C'], 'Set': ['Z', 'Z', 'X', 'Y']}

How do I add a color column to the following dataframe so that color='green' if Set == 'Z', and color='red' otherwise?

    Type       Set
1    A          Z
2    B          Z           
3    B          X
4    C          Y
Shorten.
Source Link
Mateen Ulhaq
  • 26.6k
  • 20
  • 115
  • 147
Loading
clarified question (using = may be confusing for readers)
Source Link
Loading
Question Protected by Sheldore
edited tags
Link
jpp
  • 163.3k
  • 35
  • 291
  • 349
Loading
deleted 2 characters in body
Source Link
Alex Riley
  • 174.7k
  • 46
  • 270
  • 244
Loading
Source Link
user7289
  • 33.7k
  • 28
  • 74
  • 88
Loading