0
import pandas as pd
from pandas import DataFrame
import math as ma

df = pd.read_csv("/Users/aaronhuang/Desktop/ffp/exfileCLEAN.csv")
df_top = df.head()
num = pd.read_csv('/Users/aaronhuang/Desktop/ffp/exfileCLEAN.csv', usecols=[1])


stand = round(num.std(), 4)
conf = stand * 3
avgs = round(num.mean(), 4)
avg = 19.31322603
ran = 0.425812854

i = 0
while(i < len(df['Magnitude '])):
    if(abs(df['Magnitude '][i] - avgs) > conf):
        print(df['Magnitude '][i])

    i += 1

When I try and run this, it gives me:

Traceback (most recent call last):
  File "/Users/aaronhuang/PycharmProjects/EXTTEst/Code sandbox.py", line 18, in <module>
    if(abs(df['Magnitude '][i] - avgs) > conf):
  File "/Users/aaronhuang/.conda/envs/EXTTEst/lib/python3.8/site- 
packages/pandas/core/generic.py", line 1478, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), 
a.any() or a.all().

Process finished with exit code 1

How can I fix this so I do not get this error anymore? Also When it prints the Values at the end, is there a way can I have it print out the cell in the first column in the CSV instead.

Any help would be greatly appreciated.

Thanks

Edit: Here is the start of the CSV file.

          Time   Magnitude   Magnitude error 
0             NaN         NaN               NaN
1     2455260.853      19.472             0.150
2     2455260.900      19.445             0.126
3     2455261.792      19.484             0.168
4     2455262.830      19.157             0.261
...           ...         ...               ...
6097  2457686.478      19.063             0.176
6098  2457689.480      19.178             0.128
6099  2457690.475      19.386             0.171
6100  2457690.480      19.092             0.112
  • Could you please provide a sample of your csv file? – Jeff Gruenbaum Jun 04 '20 at 01:39
  • Does this answer your question? [Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o) – Red Jun 04 '20 at 01:41
  • Hey Jeff, I have added the start of the file to the post, Thanks – Aaron Huang Jun 04 '20 at 11:41

0 Answers0