Python将数据排序并加载到Excel

时间:2018-01-15 08:20:16

标签: python-3.x pandas sorting

我正在开展一项任务,在该任务中,我扫描1000多封候选人的电子邮件,并根据需要根据其相关性分配点数。我想以排序的顺序将此数据导出为ex​​cel。排序顺序是,具有最大点(最相关的轮廓)的轮廓应该在顶部(按点desc排序)。我在Windows 7 32位上有python 3.3.5。

我搜索并了解到我可能需要pandas模块将数据存储在数据框中,然后在我的列上对其进行排序并加载到excel文件中。然后我尝试使用

安装pandas
pip install pandas
cmd以及cmd上的

(以管理员身份运行)但它会出错 -

Command "python setup.py egg_info" failed with error code 1 in c:\users\sanket~1
\appdata\local\temp\pip-build-ihqwe4\pandas\

有人可以帮我解决这个排序问题,并建议如何解决大熊猫的安装错误?或者还有其他方法可以对数据进行排序吗?

1 个答案:

答案 0 :(得分:0)

我不确定为什么你需要大熊猫才能做到这一点。我只是将它们存储为list(score,candidate)元组,然后只写为CSV:

tuples = ... # read your dataset as a list of (score,candidate) tuples
tuples.sort(reverse=True) # will sort by first element of tuples (score) in descending order
f = open('output.csv','w')
for e in tuples:
    f.write("%s,%s" % e)
f.close()

生成的CSV文件可以在Excel中打开