嘿,伙计们,我在用python工作,我只需要知道我在代码中做错了什么,这是代码的剪报,我猜是不正确的:
Uni2Rows = []
R2Rows = 0
for rows in filter:
R2Rows += 1
if R2Rows > 3 and R2Rows < 34 and rows[0] is not '':
Uni2Rows.append(rows)
GradUnderGrad = {'No.': ('Company', 'Grad', 'UnderGrad')}
for i, out2put in enumerate(Uni2Rows):
total = 0
for roww in Uni2Rows [11:12]:
if roww[out2put] is not '':
total += 1
GradUnderGrad.append(['No', twoColumns, UniRows[11], UniRows[12]])
print(GradUnderGrad)
这是我的整个程序代码,我也把我希望我的预期答案如何看,但我实际上得到了什么
####please dont copy straight up its like stealing an essay some things you cant really change theres only so many ways to do it
##Code by Angel M Gonzalez
import csv
with open('scratch.csv', 'r', errors='replace') as progfile:
progfile.close()
a = open("scratch.csv")
filter = csv.reader(a)
# Step 2: Printing
columns = { 0: 'Company', 1: 'Booth', 2: 'Full-Time', 3: 'Full-Time Visa Sponsor', 4: 'Part-Time', 5: 'Internship', 6: 'Freshman', 7: 'Sophomore', 8: 'Junior', 9: 'Senior', 10: 'Post-Bacs', 11: 'MS', 12: 'PhD', 13: 'Alumni', }
for i in columns:
print(i, columns[i])
# Step 3: Filtering and Formatting
UniRows = []
RRows = 0
for rows in filter:
RRows += 1
if RRows > 3 and RRows < 34 and rows[0] is not '':
UniRows.append(rows)
#Step 4 Expected output
employersSummary = {'No.': ('Column', 'Sum')}
for output in range(14):
total = 0
for rrows in UniRows:
if rrows[output] is not '':
total += 1
employersSummary[output] = (columns[output], total)
print(employersSummary)
#Step 4 continued
twoColumns = {
0: 'AIG',
1: 'Baylor College of Medicine',
2: 'CGG',
3: 'Citi',
4: 'ExxonMobil',
5: 'Flow-Cal Inc.',
6: 'Global Shop Solutions',
7: 'Harris County CTS',
8: 'HCSS',
9: 'Hitachi Consulting',
10:'HP Inc.',
11: 'INT Inc.',
12: 'JPMorgan Chase & Co',
13: 'Leidos',
14: 'McKesson',
15: 'MRE Consulting Ltd.',
16: 'NetIQ',
17: 'PROS',
18: 'San Jacinto College',
19: 'SAS',
20: 'Smartbridge',
21: 'Sogeti USA',
22: 'Southwest Research Institute',
23: 'The Reynolds and Reynolds Company ',
24: 'UH Enterprise Systems',
25: 'U.S. Marine Corps',
26: 'ValuD Consuting LLC',
27: 'Wipro',}
for i in twoColumns:
print(i, twoColumns[i])
#Step 4 continued
Uni2Rows = []
R2Rows = 0
for rows in filter:
R2Rows += 1
if R2Rows > 3 and R2Rows < 34 and rows[0] is not '':
Uni2Rows.append(rows)
GradUnderGrad = {'No.': ('Company', 'Grad', 'UnderGrad')}
for i, out2put in enumerate(Uni2Rows):
total = 0
for roww in Uni2Rows [11:12]:
if roww[out2put] is not '':
total += 1
GradUnderGrad.append(['No', twoColumns, UniRows[11], UniRows[12]])
print(GradUnderGrad)
这是我最后一步想要的结果:
No Company Grad UnderGrad
0 AIG, 1, 1
1 Baylor College of Medicine, 0, 0
2 CGG, 1, 0
3 Citi, 0, 1
4 ExxonMobil, 0, 1
5 Flow-Cal Inc., 0, 1
6 Global Shop Solutions, 0, 1
7 Harris County CTS, 1, 1
8 HCSS, 1, 1
9 Hitachi Consulting, 1, 1
10 HP Inc., 1, 1
11 INT Inc., 1, 1
12 JPMorgan Chase & Co, 0, 1
13 Leidos, 1, 1
14 McKesson, 0, 1
15 MRE Consulting Ltd., 1, 1
16 NetIQ, 0, 1
17 PROS, 1, 1
18 San Jacinto College
19 SAS, 1, 1
20 Smartbridge, 1, 1
21 Sogeti USA, 1, 1
22 Southwest Research Institute, 1, 1
23 The Reynolds and Reynolds Company 0 1 24 UH Enterprise Systems, 1, 1
25 U.S. Marine Corps, 1, 1,
26 ValuD Consuting LLC, 0, 1
27 Wipro, 0
Total 17 26
但这是我一直得到的,而且很烦人:
[No Company Grad UnderGrad]
我的问题是在大学最后一步,我使用的是csv文件。有人知道我做错了什么吗?我没有合并正确的列我需要一个不同的代码如果有人可以帮助我请我需要主要的帮助。你知道吗
这是我正在使用的CSV文件的链接:https://github.com/ag0715/Assign3ddhudhudhuhsashdui3hrfuwhf94839fuh38u4fhui/blob/master/CSV%20FILE
为什么你要用这么复杂的方法来读一些行,然后找到想要的字符串呢。你知道吗
下面是一个示例代码,您可以使用它来实现所需的功能:
输出
相关问题 更多 >
编程相关推荐