I have two arrays, one with 12 temperatures and the other with numbers from 1 to 12 representing the temperatures by months, but the arrays are separated, that is, they are not a dataframe or a table
temp = array([ 3.1, 3.3, 6.2, 9.2, 13.1, 15.6, 17.9, 17.5, 14.5, 10.7, 6.7, 3.7])
meses = array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
I have to write a code that returns the months that have a value greater than the average of the temp array, the average is 10,125, that is, it should return this list:
[5, 6, 7, 8, 9, 10]
I have tried to create a df with both arrays transforming them into series in this way:
values = {"temp": Temp_holland.astype(pd.Series),
"months": months.astype(pd.Series)}
pd.DataFrame(values)
but I get this error despite having transformed them:
TypeError: 'dict' object is not callable
what should I do? could it be done simply using booleans? if so how?
You don't need pandas at all, since every temperature in
temp
is at the same index as its month inmeses
, a simple boolean filter is enough:If you want to use Pandas, you could do something like:
if you want to filter the rows in which the temperature is greater than the average:
or if you want a series with the numbers of the months only: