WHAT YOU WANT TO DO
After loading the csv file in python, I would like to take out only column E, divide it into 10 or more cases, and make it possible to count how many numbers are in column E.
Problems
Python has successfully read the csv file, but only the column itself does not work.
Also, counting how many numbers are more than 10 after dividing them into for statements is not successful.In that case, please let me know if I should use sum or count on counter.
Thank you for your cooperation.
python csv
If you don't want to process it into something later, it would be faster to take it out of each row than to take it out alone.
For example, suppose you have this data.csv
file.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0,1,2,3,40,5,6,7,8,9
0,1,2,3, 4,5,6,7,8,9
0,1,2,3,14,5,6,7,8,9
0,1,2,3, 4,5,6,7,8,9
0,1,2,3,10,5,6,7,8,9
0,1,2,3, 4,5,6,7,8,9
0,1,2,3,24,5,6,7,8,9
0,1,2,3, 4,5,6,7,8,9
0,1,2,3,34,5,6,7,8,9
These programs can count more than 10 numbers.
import csv
csvdata = [ ]
with open('data.csv', mode='r', encoding='shift_jis') asfp:
csvdata=list(csv.reader(fp))
ge10 count = 0
for row in csvdata:
colE=int(row[4])
if colE>=10:
ge10 count + = 1
print(ge10 count)
I will process it into something later, so if you want to extract it, please refer to this article.
I want Python to take out only the nth of each element in the two-dimensional array and arrange it as an element
After loading the program:
columnE=[row[4]for row in csvdata]
ge10 count2 = 0
for strE in columnE:
colE=int(strE)
if colE>=10:
ge10 count 2 + = 1
print(ge10 count2)
© 2024 OneMinuteCode. All rights reserved.