Click here to Skip to main content
15,886,026 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:
Python
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)
print(dfArxika.columns)

A=dfArxika[9]

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)
    else:
        IA[i]=(2.2*(math.log10(A[i]/66))+5.5)
Posted
Updated 12-Nov-20 5:54am
v3

1 solution

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

Please study The Python Tutorial — Python 3.7.9 documentation[^] for correct syntax.
 
Share this answer
 
Comments
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)

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