'Why when calling and using a specific year in a dataset does python return it as non-callable?

So I am creating a code to find the time-varying Value-at-Risk using yearly windows from a file I have imported and shown below. enter image description here

When creating the code to find the yearly daily returns in Year 1964 for example (from 1/2/1964 to 12/31/1964) as a baseline distribution, and calculate the value from a 2.5% return. However when I run this code I get the error ( 'DataFrame' object is not callable). Is there way to workaround this or fix it?

    year1=data(YEAR[0])
    data1_location = (year1)*2.5/100    # 2.5% is the rate for this formula
    extreme = [int(data1_location)]        # sorts the data location I created
    print("The extreme value that is asbsociated with the lower 2.5% is"(data1_location))


Solution 1:[1]

It seems that you want to create a subset of your original DataFrame for a given year.

However, YEAR[0] will be equal to 1964, which you cannot use directly for indexing your DataFrame.

For getting all items for the year 1964, use

year1 = data[data['yyyy'] == '1964']

Next thing is that year1 is again a data frame which you cannot use in an arithmetic operation. Probably you want something like this:

year1['value'] = year1['RET_SP500']*2.5/100

or similar (it's not quite clear to me from your question what you need to caluclate). This creates a new column with the result of the formula. Then you can operate on this column, for example create a list of entries or find the maximum or minimum value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gerd