我正在尝试将一个文件排序为二维数组。文件看起来像这样
12345 1 893.33
32214 1 343.50
23422 3 903.22
57373 2 893.55
68483 5 329.00
99376 9 329.66
12345 2 999.99
32214 4 892.77
23422 4 895.33
23422 2 492.77
57373 6 985.84
68483 10 1224.90
99376 11 234.56
12345 8 494.44
68483 7 595.55
12345 12 322.22
68483 9 567.85
99376 3 788.77
99376 12 956.66
32214 8 777.77
32214 10 888.88
57373 9 256.56
我现在的代码是这样的,它返回的文件和它看起来的一模一样
def print_report(sales_data):
with open(sales_data) as myfile:
sales = myfile.read()
print(sales)
Enter the name of the sales ids file: salesids.txt
Enter the name of the sales data file: salesdata.txt
--------Annual Sales Report--------
ID QT1 QT2 QT3 QT4
12345 1 893.33
32214 1 343.50
23422 3 903.22
57373 2 893.55
68483 5 329.00
99376 9 329.66
12345 2 999.99
32214 4 892.77
23422 4 895.33
23422 2 492.77
57373 6 985.84
68483 10 1224.90
99376 11 234.56
12345 8 494.44
68483 7 595.55
12345 12 322.22
68483 9 567.85
99376 3 788.77
99376 12 956.66
32214 8 777.77
32214 10 888.88
57373 9 256.56
我需要对列表进行排序,以便每个ID(12345)及其下一个月的正确月份都有右侧的销售数据,并将其排序到右侧的季度(QT1=1-3 QT2=4-6 QT3=7-9 QT4=10-12)
我如何做到这一点?你知道吗
应该是这样的
您可以在纯Python中尝试以下解决方案:
上述输出为:
请随时提出任何问题,或如果您需要任何有关代码的澄清。你知道吗
相关问题 更多 >
编程相关推荐