So I was working on this project but I ran stuck (again), I have a excel file with 344 columns and he should check if a cell has a certain and if it has then it should continue and print a word. If it doesnt then it should also continue but then without printing. I believe that I have the right code but it still returns an error.
JavaScript
x
19
19
1
import matplotlib.pyplot as plt
2
import numpy as np
3
import pandas as pd
4
from pygef.gef import ParseGEF
5
6
#Read *.gef file
7
gef = ParseGEF("./CPT000000052185_IMBRO_A.Gef")
8
gef.df.to_csv("./CPT000000052185_IMBRO_A.GEF")
9
file = pd.read_csv("./CPT000000052185_IMBRO_A.GEF", usecols=['friction_number' , 'depth'])
10
print (file)
11
12
FrictionNumber = file.friction_number
13
print (FrictionNumber)
14
FrictionNumber.dtypes
15
16
for i in FrictionNumber:
17
if (0.2 < FrictionNumber [i] < 2.0):
18
print ("Gravel")
19
This is the code, and it returns this error:
JavaScript
1
3
1
cannot do label indexing on <class 'pandas.core.indexes.range.RangeIndex'> with these indexers [1.4986376021798364] of <class 'float'>
2
``` (1.4986... is the value of the first cell)
3
If I’m right it returns this because the value in the cell is a float. How can I make this work with a float?
Advertisement
Answer
You already was iterating over FrictionNumber
with i
, so you could just directly use the value i
for comparing.
JavaScript
1
19
19
1
import matplotlib.pyplot as plt
2
import numpy as np
3
import pandas as pd
4
from pygef.gef import ParseGEF
5
6
#Read *.gef file
7
gef = ParseGEF("./CPT000000052185_IMBRO_A.Gef")
8
gef.df.to_csv("./CPT000000052185_IMBRO_A.GEF")
9
file = pd.read_csv("./CPT000000052185_IMBRO_A.GEF", usecols=['friction_number' , 'depth'])
10
print (file)
11
12
FrictionNumber = file.friction_number
13
print (FrictionNumber)
14
FrictionNumber.dtypes
15
16
for i in FrictionNumber:
17
if (0.2 < i < 2.0):
18
print ("Gravel")
19