Click here to Skip to main content
15,176,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in Python and I would like to ask something.

My code reads a csv file. I want to use one column. I want to use an equation which calculates, depending on the value of the column I want to use, several values. I am using commands for and if.

but command window shbows me the error:

TypeError: 'Series' object is not callable

Could you help me?

What I have tried:

my code:
import math
import pandas as pd
import matplotlib as mpl
import numpy as np

dfArxika = pd.read_csv('AIALL.csv', usecols=[0,1,2,3,4,5,6,7,8,9,10], header=None, index_col=False)


for i in range(len(A)):
    if (A[i] >= 4.8 and A[i] < 66):
        IA[i]= (2.2*(math.log10(A[i]/66))+5.5)
    elif (A[i] >= 66):
        IA[i]= 3.66*(math.log10(A[i]/66)+5.5)
Updated 12-Nov-20 6:54am

1 solution

Index values on lists must be in square brackets [ and ], not parentheses.
    if (A[i] >= 4.8 and A[i] < 66):
# etc.

Please study The Python Tutorial — Python 3.7.9 documentation[^] for correct syntax.
Member 14991075 12-Nov-20 9:06am
Excuse me , I have tried your solution but command window shows me:
TypeError: cannot do label indexing on <class 'pandas.core.indexes.range.rangeindex'=""> with these indexers [122.59] of <class 'float'="">
Richard MacCutchan 12-Nov-20 9:15am
Your for statement is wrong (which I missed). You are trying to use i as the index to each element in A so it should be:
for i in range(len(A)):

Alternatively if you leave the for statement as is then you do not need A[i] as it is set to iterate over each element in the list, so you just replace each occurrence of A[i] with simply i. Although I strongly recommend you stop using single characters for your variables and use meaningful names.

Also as I suggested above, go and work through the Python tutorials so you get a proper understanding of the language and its syntax.
Member 14991075 12-Nov-20 10:47am
ok, I tried this but it shows me:
NameError: name 'IA' is not defined (IA is the equation I show you in my code solution above)
Richard MacCutchan 12-Nov-20 10:59am
Which line does that message refer to? Please use the Improve question link above, and add the details to your original question.
Member 14991075 12-Nov-20 11:05am
This message refer to line
IA=3.66*log10(A(i)/66)+5.5 (line 14)
Richard MacCutchan 12-Nov-20 11:48am
Pleas do what I asked and update your question with the actual code and the error message.
Member 14991075 12-Nov-20 11:56am
I just did it
Richard MacCutchan 12-Nov-20 12:07pm
IA does not exist yet, so the following line makes no sense.
        IA[i]= (2.2*(math.log10(A[i]/66))+5.5)

You cannot use an index address on a variable that does not yet exist. Nor can you learn a programming language from questions in forums like this. Make things easy for yourself, go to the tutorials page I gave you and study the language in proper detail.
Member 14991075 13-Nov-20 3:20am
I know, but I am reading so much that I have confused. Could you please tell me what to in order to finish my code?
Richard MacCutchan 13-Nov-20 3:36am
Yes, do what I keep suggesting. You can work through the basics in the tutorial (sections 2 through 6) in a few hours, so it is time well spent. It gives clear details of how to create and manage the different variable types, single items, lists, dictionaries, tuples etc. Full understanding of those is most important for what you are trying to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900