title: Colour scatter plot by column Plotly
body: <p>I would like to create a scatter plot with 3 variables: <code>Age</code>, <code>Value</code> and <code>City</code>. How can I colour the plot by <code>City</code>?</p>
  <p>Current output is a simple scatter plot of <code>Value</code> against <code>Age</code>:
  <a href="https://i.stack.imgur.com/AALDl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AALDl.png" alt="enter image description here" /></a></p>
  <p>Current Code:</p>
  <pre><code>import datetime
  import plotly.offline as py
  import plotly
  import plotly.graph_objects as go
  fig = go.Figure()
  
  fig.add_trace(go.Scatter(x= data1['Age'], y = data1['Value'], mode='markers', name='lines+markers'))
  fig.show()
  </code></pre>
  <hr />
  <p>Update:</p>
  <p>Tried:</p>
  <pre><code>import plotly.express as px
  
  fig = px.scatter(data1, x=data1['Age'], y=data1['Value'], color=data1['City']) 
  fig.show()
  </code></pre>
  <p>and caught error:</p>
  <pre><code>KeyError: (nan, '', '', '', '')
  </code></pre>
  <hr />
  <p>Update:</p>
  <p><code>Age</code> and <code>Value</code> have been cleaned. Here are some unique values for <code>City</code>(sorry to change the column). There are some messy figures.</p>
  <pre><code>       ['NT', 'WAIKATO', 'VICTORIA', 'South Australia', 'OTHER', 'ON',
         'Nsw', 'IL', 'MD - MARYLAND', 'ABU DHABI', 'VIENNA', 'TX',
         'VILKAVISKIS', 'NY', 'BALEARES', 'UK', 'GLOUCESTERSHIRE',
         'LA MANCHE', 'TEXAS', 'DUBAI', 'ENGLAND', 'ITALY', nan,
         'GREATER LONDON', 'BEDFORDSHIRE', 'HEREFORDSHIRE',
         'BADEN-WÃ?RTTEMBERG', 'Australian Capital Territory',
         'ABERDEENSHIRE', 'OXFORDSHIRE', 'LONDON', 'BC', 'SK',
         'NOORD-HOLLAND', 'UNITED KINGDOM', 'New South Wales', 'Brookdale',
         'Western Australia', 'GALWAY', 'Queensland', 'TOKYO',
         'HAUTE-GARONNE', 'WORCESTERSHIRE', 'CALIFORNIA', 'JAPAN',
         'NORTHUMBERLAND', 'NJ - NEW JERSEY', 'GLOS', 'DORSET', 'TENNESSEE',
         'BANGKOK', 'CANTERBURY', 'WEXFORD', 'MIDDLESEX', 'SURREY', 'MI',
         'NEVADA', 'KENTUCKY', 'NEW YORK', 'ZUID-HOLLAND', 'HONG KONG',
         'ESSEX', 'FL', 'LILLEHAMMER', 'DEVON', 'NEW TERRITORIES', 'KENT',
         'THAILAND', 'Pyrmont', 'SINGAPORE', 'FRIBOURG', 'CAIRO',
         'QUEENSLAND', 'HAMPSHIRE', 'NEW JERSEY', 'WEST MIDLANDS',
         'MICHIGAN', 'NONE', 'WI', 'BARNET', 'STAFFS', 'WARWICKSHIRE'...]
  </code></pre>