Japanese processing of csv files in python

Asked 2 years ago, Updated 2 years ago, 59 views

Downloaded time: 11/11/2019 16:04:33                  

                staying overnight at a temple
Wind direction (m/s) per hour (month/day)

2016 12 23 5 9.6 West
2016 12 23 6 9.8 West
2016 12 23 7 10.6 West
2016 12 23 8 10.4 West
2016 12 23 9 10.5 West
2016 12 23 10 9.1 West
2016 12 23 11 8.1 West-northwest
2016 12 23 12 7.8 West-northwest
2016 12 23 13 6.8 West-northwest
2016 12 23 14 6.3 West-northwest
2016 1223 156.2 West-West
2016 12 23 166.5 West-northwest
2016 12 23 17 6.3 Northwest
2016 12 23 18 6.3 West-northwest
2016 1223 195.4 West-northwest
2016 12 23 20 3.9 West-northwest
2016 12 23 214 West-northwest
2016 12 23 22 4.6 Northwest
2016 12 23 23 24 Northwest

The method of summarization is to count the number of wind speeds of 10 m/s or more and meet the six directions of west, northwest, northwest, northwest, northwest, and north in 16 directions.Reading the csv file and counting the number of wind speeds above 10 m/s is made up of the following code:
I stumble when I count the number of items that meet a specific orientation.
Is it possible to categorize Japanese in the first place?

The current code is listed below.
Thank you for your cooperation.

import csv

    f=open("Terayuki 12-1.csv", "r")
    reader=csv.reader(f)
    next(reader);next(reader);next(reader);next(reader);next(reader)

    count = 0
    For row in reader:
        colE=float(row[4])
        if colE>=10:
            count+=1
            print(count)

    f.close()

python csv

2022-09-29 22:01

1 Answers

You can simply use the list and the in operator.
Determine if the list contains specific elements by Python's in operator

import csv

trgDir=['West', 'West-West', 'North-West', 'North-West', 'North-West', 'North-West', 'North-West']

f=open("Terayuki 12-1.csv", "r")
reader=csv.reader(f)
for i in range (5):
    next(reader)

count = 0
For row in reader:
    colE=float(row[4])
    if(colE>=10) and (row[5]intrgDir):
        count+=1
        print(count)

f.close()


2022-09-29 22:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.