I am completely new to all coding so forgive any mistakes in asking the question and please explain like I am 5. I have a file that I've converted to a dataframe but when I try to find a row number corresponding to a specific value it shows up as empty dataframe with a blank for indexes. When I use len(pdf.index)
it shows that I have 41 rows. When I try pdf.empty
I get an output of false
. When I use print(pdf.loc[[8]])
it shows row number 8 and the corresponding values. But when I try print(pdf.loc[pdf['b'] == 0.078162596])
to find the row number corresponding to that value I get this output.
Empty DataFrame
Columns: [a, b, c]
Index: []
This the the code I used to convert the file into a dataframe and the accompanying output.
pdf = pd.read_fwf('POSCAR_FIRST_LAYER_MANIPULATION copy.txt',header=None,names=['a', 'b', 'c'])
print(pdf)
0 POSCAR file written by Ovito 3.0.0-dev592 NaN
1 1.0 NaN NaN
2 17.0490970612 0.0000000000 0.000000
3 -0.2785043757 16.9197069925 0.000000
4 9.1773295512 2.1229179060 26.650587
5 Al NaN NaN
6 33 NaN NaN
7 Direct NaN NaN
8 0.871711731 0.078162596 0.687544
9 0.760161042 0.924855471 0.689709
10 0.139614120 0.565118968 0.687534
11 0.657146931 0.564061284 0.690766
12 0.566381097 0.062637828 0.709589
13 0.402278483 0.313420027 0.685133
14 0.265235394 0.675979972 0.690942
15 0.172629282 0.802049637 0.692856
16 0.779488027 0.210808992 0.678538
17 0.893642426 0.794784069 0.703213
18 0.278293014 0.198673010 0.728557
19 0.369670391 0.561983645 0.700044
20 0.463950276 0.948694766 0.688976
21 0.265022933 0.467927545 0.680167
22 0.451571882 0.184303001 0.718000
23 0.596131206 0.206098735 0.734343
24 0.125493318 0.328866482 0.689191
25 0.514403701 0.671504021 0.692916
26 0.157217637 0.091310225 0.672789
27 0.301339477 0.911068797 0.704346
28 0.651949406 0.336005211 0.688029
29 0.027625797 0.686297476 0.707778
30 0.519436598 0.489014864 0.687087
31 0.981806457 0.443361163 0.704743
32 0.751180947 0.722405374 0.675096
33 0.418921798 0.795465171 0.685067
34 0.868863404 0.592041790 0.698836
35 0.035270356 0.972233951 0.690336
36 0.358790606 0.075232171 0.693458
37 0.767691195 0.467198342 0.689382
38 0.021950169 0.196752921 0.681510
39 0.894401014 0.301784605 0.696536
40 0.618448853 0.807215154 0.688638
I tried to get rid of the whitespace but that did nothing. How do I get this to not show up as an empty dataframe and get the corresponding row number to the value I enter. Thank you!
You can't compare floating point numbers directly. Floating point numbers are an approximation. Pandas is showing you the first 9 decimal places, but the number actually has 15 decimal places. You need to do something like
print(pdf[pdf['b']-0.078162).abs() < 0.00001])