Допустим, у меня есть документ Excel в следующем формате.Я читаю вышеупомянутый документ Excel с пандами и строю графики, используя matplotlib и numpy.Все отлично!
Buttttt ..... Я не хочу больше ограничений.Теперь я хочу ограничить свои данные, чтобы сортировать только по определенным зенитным и азимутальным углам.Более конкретно: я хочу, чтобы зенит был только между 30 и 90, и я хотел только азимут, когда он между 30 и 330
Air Quality Data
Azimuth Zenith Ozone Amount
230 50 12
0 81 10
70 35 7
110 90 17
270 45 23
330 45 13
345 47 6
175 82 7
220 7 8
Это пример того типа ограничений, который я ищу.
Air Quality Data
Azimuth Zenith Ozone Amount
230 50 12
70 35 7
110 90 17
270 45 23
330 45 13
175 82 7
Вот мой код:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime
P_file = file1
out_file = file2
out_file2 = file3
data = pd.read_csv(file1,header=None,sep=' ')
df=pd.DataFrame(data=data)
df.to_csv(file2,sep=',',header = [19 headers. The three that matter for this question are 'DateTime', 'Zenith', 'Azimuth', and 'Ozone Amount'.]
df=pd.read_csv(file2,header='infer')
mask = df[df['DateTime'].str.contains('20141201')] ## In this line I'm sorting for anything containing the locator for the given day.
mask.to_csv(file2) ##I'm now updating file 2 so that it only has the data I want sorted for.
data2 = pd.read_csv(file2,header='infer')
df2=pd.DataFrame(data=data2)
def tojuliandate(date):
return.... ##give a function that changes normal date of format %Y%m%dT%H%M%SZ to julian date format of %y%j
def timeofday(date):
changes %Y%m%dT%H%M%SZ to %H%M%S for more narrow views of data
df2['Time of Day'] = df2['DateTime'].apply(timeofday)
df2.to_csv(file2) ##adds a column for "timeofday" to the file
Итак, на данный момент это весь код, который входит в создание CSV, который я хочу отсортировать.Как мне поступить с сортировкой
'Zenith' and 'Azimuth'
Если бы они соответствовали критериям, указанным выше?
Я знаю, что мне понадобятся операторы для этого.Я попробовал что-то подобное, но это не сработало, и я искал немного помощи: