我刚开始用Python编写代码。
我正在对从Scopus数据库中提取的文件数据库做一些分析。我用.csv下载了数据库,然后对其进行了一些分析和过滤。在进行初步分析之后,我将文件保存在.xlsx中,这是数据库的当前格式。
我正在试图获取一个图表,显示一个日志在数据库中出现的次数。
我使用value_counts()命令提取了值,然后将这些数据存储到一个有两列(Journal和Count)的表中:
journals_count = data['Source_title'].value_counts().reset_index()
journals_count.columns = ['Journal', 'Count']
Journal Count
0 IEEE Transactions on Industrial Informatics 40
1 Expert Systems with Applications 37
2 Applied Energy 20
3 International Journal of Production Economics 13
4 Energy and Buildings 11
5 Information Sciences 11
6 International Journal of Information Management 10
7 Decision Support Systems 9
8 International Journal of Advanced Manufacturing 9
9 International Journal of Production Research 8
10 European Journal of Operational Research 7现在,我想使用以下代码从这个表中创建一个条形图,其中x轴上有Journal名称,y轴上有Count值:
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(journals_count['Journal'], journals_count['Count'])问题是,我获得了以下错误:
ValueError: could not convert string to float: 'Service Industries Journal''Service Industries Journal'是最后一个Count值等于1的日志。
我怎么能把它画成Python呢?
发布于 2018-04-20 13:01:22
我认为您应该将journals_count['Journal']中的journals_count['Journal']值枚举到[1, 2, 3, ...]中。之后,用xticks将这些值映射到您的xticks。
x = np.arange(len(journals_count['Journal']))
plt.xticks(x, journals_count['Journal'])
plt.plot(x, journals_count['Count'])
plt.show()https://stackoverflow.com/questions/49942180
复制相似问题