Issue
Good morning everyone,
Basically, I am doing a Dataframe to the number of won in a lottery here where I live. I am stuck in plotting a Dataframe that I created from a CSV file. This is my code:
data_file = pd.read_csv('Jugadas_Ganadas.csv')
data_file.set_index('Date', inplace=True)
df = pd.DataFrame(data_file)
pickle_out = open('Pega3_Ganados.pickle', 'wb')
pickle.dump(df, pickle_out)
pickle_out.close()
fi = plt.figure()
ax1 = plt.subplot2grid((1, 1), (0, 0))
data_analysis = pd.read_pickle('Pega3_Ganados.pickle')
print data_analysis
After printing the data analysis I get the following framework.
Values
Date
15/07/2017 [660]
16/07/2017 [40]
17/07/2017 [300]
18/07/2017 [40]
19/07/2017 [80]
After I confirm that I have a framework into my variable I try to plot it in a matplotlib graph by using this script.
fi = plt.figure()
ax1 = plt.subplot2grid((1, 1), (0, 0))
data_analysis['Values'].plot(ax=ax1, label='Ganadas')
plt.legend(loc=4)
plt.show()
However, I get the following error:
TypeError: Empty 'DataFrame': no numeric data to plot
Solution
I think column values
contains lists, so need select first value of lists by str[0]
:
print (type(df.loc[df.index[0], 'Values']))
<class 'list'>
data_analysis['Values'].str[0].plot(ax=ax1, label='Ganadas')
If type of values is string
use strip
and astype
:
print (type(df.loc[df.index[0], 'Values']))
<class 'str'>
data_analysis['Values'].str.strip('[]').astype(int).plot(ax=ax1, label='Ganadas')
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.