1

I have two columns: genres (more than 10 unique) and price and I want to compare them using scatter plot. How can I write string names in x axis?

price 2.99 3.54 7.00 and so on

genre fiction drama psychology and so on

Another option: convert string to category and somehow convert category numbers to string during graphing. Is it possible?

df['genre'] = df['genre'].astype("category").cat.codes 
Plot = df.plot.scatter(x='genre',
                      y='price',
                      c='DarkBlue')

2 Answers 2

2

You can leave the genre column as object, aka string, Dtype in pandas and plot it. Try running just the line below.

df.plot.scatter(x='genre', y='price', c='DarkBlue')

Here is a working example.

import seaborn as sns
iris = sns.load_dataset('iris')

iris.plot.scatter("species", "sepal_length")
Sign up to request clarification or add additional context in comments.

4 Comments

No, it says: "scatter requires x column to be numeric"
@Ksenia: what version of Pandas are you on? This works for me on 1.0.3.
@mechanical_meat: I have the 1.0.1. Maybe that's a problem.
0

I think you are asking about axis labels?

if so it's as simple as this

plot.xlabel("Genre")

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.