1

enter image description hereI'm trying to plot a dataframe with two columns:

    Compound_ID,Averages
  0  M0001,0.75
  1  M0002,0.87
  2  M003,0.45

Instead of showing the 'Compound_ID' on the x axis it is showing the index. When I explicitly try to plot, it raises and error.

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df = pd.read_csv('teste.csv')
plt.plot(df['Averages'], df['Compound_ID'])
plt.show()


AttributeError: 'Series' object has no attribute 'find'

It is probably something easy to solve, but can someone take a look at my code?

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df = pd.read_csv('teste.csv')
plt.plot(df['Averages'])
plt.show()
2

1 Answer 1

3

You can do this:

plt.plot(df['Averages'])
plt.xticks(range(len(df['Compound_ID'])) , df['Compound_ID'])

This way you plot xticks separately. The first element is numerical indexes, second - names.

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.