Skip to content

Commit ecabf6d

Browse files
committed
given frequencies, subset a given larray via labels on its time axis
1 parent 82cc512 commit ecabf6d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

larray_editor/editor.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,35 @@ def tree_to_dataframe(root):
135135
return pd.DataFrame(rows, columns=root.data)
136136

137137

138+
# Extract frequencies from given dataset and subset accordingly
139+
def freq_eurostat(freqs, la_data):
140+
# If "TIME_PERIOD" exists in la_data's axes names, rename it to "time"
141+
if "TIME_PERIOD" in la_data.axes.names:
142+
freq_data = la_data.rename(TIME_PERIOD='time')
143+
144+
a_time = []
145+
146+
for freq in freqs:
147+
# str() because larray labels are not always strings, might also return ints
148+
if freq == 'A':
149+
a_time += [t for t in freq_data.time.labels if '-' not in str(t)]
150+
elif freq == 'Q':
151+
a_time += [t for t in freq_data.time.labels if 'Q' in str(t)]
152+
elif freq == 'M':
153+
a_time += [t for t in freq_data.time.labels if '-' in t and 'Q' not in str(t)]
154+
155+
# Maintain order and use set for non-duplicates
156+
a_time = sorted(set(a_time))
157+
158+
if len(freqs) == 1 and freq[0] in ['A', 'Q', 'M']:
159+
freq_value = str(freqs[0])
160+
else:
161+
freq_value = freqs
162+
163+
# Return with row and colum-wise subsetting
164+
return freq_data[freq_value, a_time]
165+
166+
138167

139168
class FrequencyFilterDialog(QDialog):
140169
def __init__(self, available_labels, parent=None):

0 commit comments

Comments
 (0)