I am trying to plot second column of a csv file but second column returning the nan values. If I set the dtype= None or dtype= str will return the string values which at the end cause plotting in the wrong way in Y axis. any comment would appreciated.
second column in csv include values from 80-99% which save before like this snippet
numpy.savetxt('loss_acc_exp4.csv', numpy.c_[losses, ACCes], fmt=['%.4f', '%d %%'], header= "loss, acc", comments='', delimiter = ",")
Here is snippet for plot the csv file
import numpy
import matplotlib.pyplot as plt
acc_history = numpy.genfromtxt("loss_acc_exp4.csv", delimiter=",",
skip_header=1, usecols=(1))
num_epochs = 151
epochs = range(1, num_epochs)
plt.figure(figsize=(10,6))
plt.plot(epochs, acc_history[::2], '-b', label='Training accuracy') #plot odd rows
plt.plot(epochs, acc_history[1::2], '-r', label='Validation accuracy') # plot even rows
plt.legend()
plt.xlabel('Epoch')
plt.ylabel('accuracy')
plt.xlim(0.01,151)
plt.show()
Data in csv look like this
import pandas as pd
def convert_percent(val):
"""
Convert the percentage string to an actual floating point percent
- Remove %
- Divide by 100 to make decimal
"""
new_val = val.replace('%', '')
new_val = pd.Series([new_val]).astype(float)
return (new_val) / 100
acc_history = pd.read_csv("loss_acc_exp4.csv", delimiter=",", header=0,
usecols=[1], dtype=None)
acc_history[:].apply(convert_percent)
it is returning ValueError: ('setting an array element with a sequence.', 'occurred at index acc')