3
import matplotlib.pyplot as xy
a= [1,3,5,3,'',4]
b=[1,2,3,4,5,6]
xy.plot(b,a)
xy.show()

This code is throwing an error saying "ValueError: could not convert string to float:"

1
  • use np.nan, not '' Commented Jun 22, 2015 at 18:12

1 Answer 1

3

Create 2 new lists, that only contain valid data, which is then used for plotting. The example below skips this copying step and assumes that data from a and b can be deleted without causing any issues. If in doubt, just create a copy of both before doing the for-loop.

a=[1,3,5,3,'',4]
b=[1,2,3,4,5,6]

for index in range(len(a)-1):
    if a[index] is '':
        del a[index]
        del b[index]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.