Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite39f938

Browse files
committed
fixed wrong column when calling fxn
1 parent6850b38 commite39f938

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

‎Module6/iris_script.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
importsys
4+
importcsv
5+
6+
defread_in_csv(file_path):
7+
f=open(file_path)
8+
my_file=csv.reader(f)
9+
returnmy_file
10+
11+
defget_column_unique(in_file,col_number):
12+
col_list= []
13+
my_file=read_in_csv(in_file)
14+
forrowinmy_file:
15+
col_list.append(row[col_number])
16+
unique_vals=set(col_list)
17+
unique_length=len(unique_vals)
18+
returnunique_length
19+
20+
defcount_things(in_file,col_number):
21+
my_dict= {}
22+
my_file=read_in_csv(in_file)
23+
24+
# loop through dictionary to track name and count
25+
forrowinmy_file:
26+
key_name=row[col_number]
27+
28+
# for every row, check if the class_name is in the dictionary
29+
ifkey_nameinmy_dict:
30+
my_dict[key_name]=my_dict[key_name]+1
31+
32+
# if not, add it, and set the count to 1
33+
else:
34+
my_dict[key_name]=1
35+
36+
returnmy_dict
37+
38+
39+
# have the user specify input file
40+
my_file="./iris.csv"
41+
42+
unique_vals=get_column_unique(my_file,4)
43+
count_classes=count_things(my_file,4)
44+
45+
print(unique_vals)
46+
print(count_classes)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp