Python Numpy 数据处理:降序排序和可视化发文次数
以下是使用 Python Numpy 库对数据进行处理,并进行降序排序和数据可视化的代码:
import numpy as np
import matplotlib.pyplot as plt
# 创建数据
data = np.array([[2014, 18], [2015, 17], [2016, 19], [2017, 10], [2018, 10],
[2019, 13], [2020, 6], [2021, 8], [2022, 5]])
# 降序排序
sorted_data = data[data[:, 1].argsort()[::-1]]
# 取出时间和发文次数
time = sorted_data[:, 0]
count = sorted_data[:, 1]
# 可视化
plt.bar(time, count)
plt.title('Number of Posts per Year')
plt.xlabel('Year')
plt.ylabel('Number of Posts')
plt.show()
执行上述代码后,将得到一张降序排序后的柱状图,如下所示:

原文地址: https://www.cveoy.top/t/topic/oYDt 著作权归作者所有。请勿转载和采集!