0

I use pandas to read my csv file and turn two columns into arrays as independent/dependent variables respectively. the data reading, array-turning trans and value assign

Then when I want to use matplotlib.pyplot to plot the line charts out, it turns out that 'numpy.ndarray' objects has no attribute 'find'.

import numpy as np
import matplotlib.pyplot as plt
plt.plot(x,y)

1 Answer 1

1

The problem is probably with your dtypes, assuming your data are in df check the df.dtypes. Columns you are trying to plot must be numeric (float, int, bool).

I guess that at least one of the columns you are plotting has object dtype, try to find out why (maybe missing values were read as some sort of string, or everything is just considered string) and convert it to correct type with astype, i.e.

df['float_col'] = df['float_col'].astype(np.float64)

Edit:

If you are trying to plot date use, make sure that dtype is actually a date i.e. datetime64[ns] and use matplotlibs dedicated method plot_date

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

2 Comments

Thanx for your prompt answering and sharing. and the problem is dtype. The thing is that, I want to plot a line char whose x axes is date, (str I guess), and y axes is the discrete rate (float I guess). How can I plot it out with pyplot?
maek sure your dtype is not object but some sort of datetime, i.e. datetime64 or M<8. Then use matplotlib.pyplot.plot_date

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.