Python: How to count the desired data values in a csv file

Asked 2 weeks ago, Updated 2 weeks ago, 0 views

I want to count only the numbers between 500 and 550 in the csv file, how do I enter them? I used a Pandas module, and I want to get the result of a strong number (count) x 25 at the end, how should I input it?

*Python 3.8.5 Anaconda

def surface_area_of_cotter(data_set,x_coordinate,y_coordinate): 
    dictio = {}
    count = 0
    s = pd.Series(range(500,550))
    data_set = pd.read_csv("elevation_data_dam.csv", header=None)
    for s in data_set:
        count += 1
        if s in dictio:
            dictio[int(s)] += 1
        else:
            dictio[int(s)] = 0
    if count ==0.0:
        return 0
    else:
        return (count*25)

I can't upload the csv file, so I'll upload a screenshot.

It looks like this, and it's about 883 rows x 1189 columns

python coding csv count

2022-09-20 16:21

1 Answers

Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pandas as pd

>>> pd.util.testing.makeDataFrame()

Warning (from warnings module):
  File "C:\PROGRAMS\Python3864\lib\site-packages\pandas\util\__init__.py", line 12
    import pandas.util.testing
FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
                   A         B         C         D
xJkgimXOO1 -2.068095 -0.862084  1.174664  0.605598
VMJRWwfx2I -0.426533  1.538165 -0.266820  0.865586
B5TJ7K49xv -0.711415 -0.764578 -0.152343 -0.846417
bjvOIK3VqT -0.138098 -0.429742 -1.407439 -0.517214
FBS3NstvO6  2.199321 -0.297894 -0.272281  0.904358
9bQerRF8Cf  0.155426  0.938006  1.445933  0.708087
UmpISw6iWn -0.194906 -0.991698  0.994875  0.558863
79VZoNtvyP -0.250903 -0.064654  0.101859 -0.164328
EbAXsNp8WA  0.585207  1.158592  2.258985 -0.117060
WTSoY8Nfux  0.525517  0.382023 -0.768719 -1.195720
rXIRbiOIPS  1.310514  0.485413  0.516931  0.681023
Lq5Vv3xH5l  0.290427  0.764235  0.260702  1.394933
8NEbjkhdNM -0.664036  1.566563 -0.769363 -1.659315
Q8oYllUF2d  0.407795 -1.518604 -1.113792  0.524132
mGbdXdaBrF -1.032162 -0.689032 -1.184794  1.680902
egws9vRTaw -0.876018  0.879759 -0.159719 -0.359441
dHGXXuP1oT -0.561575  0.447506  0.998484 -0.179926
9jCr4T1ABM  0.660226  0.227815  0.595446 -0.862358
nzC0wNkANA  1.327197 -2.228301  0.209119  0.321083
f1gbUQ2FR7 -1.150391 -0.190378 -2.058716 -0.449486
WbcpUcDZMj  0.561320  0.945240  0.902691 -0.389810
r2qfmlr3iF  1.093691 -0.467255 -0.032177 -0.248554
QrYstxgunK -1.268535 -0.905966 -1.452583  0.878582
r3zi3RY5us  0.704596 -1.270919  0.345733  1.423350
hnhvkmueIM  0.646636  0.496981  1.015088  1.113452
eKuxSLxIGa -1.702409  1.232963  0.089731 -0.480037
VWD7AF5T9j  0.281270 -0.246131  1.226429  2.118941
22zkhvcLZd -1.977567 -0.922947  0.886425  0.328335
hPYZF9y3IB -1.137796 -1.129235 -1.516711 -0.465867
XuxHS1HzZ3 -0.574693  0.826713 -0.487397  0.303155
>>> a = pd.util.testing.makeDataFrame()

>>> a > .5
                A      B      C      D
dXkJTlAkc9   True  False  False  False
Ln09Q1q7g9  False  False  False   True
dIQgDaq9b2  False  False  False  False
xWFDToUkr7   True  False  False  False
xH5mELuojY   True   True  False  False
CjpqxkePjD   True  False  False   True
xY9RGCqhAO  False   True  False  False
EKnui571zS   True  False  False  False
ghJrNKJuY8   True  False   True  False
H8w4cuIphV   True  False   True  False
ALxoOl1jJb  False   True  False   True
XJ4nlr8XK0  False  False   True   True
ddgrXORpkh  False  False   True   True
oOsZDhi00d  False  False   True   True
Ycer5SJX9T  False  False  False   True
O3WO2G2eOv  False   True   True   True
qLhZJtZuR3  False   True   True   True
eiBuxfXWyM  False  False  False  False
VdxcO7Gztz  False  False  False  False
xoRXaQcMY8  False   True   True  False
jsc3WBYqfO   True   True  False   True
D3XaUA5wxS  False  False  False  False
z8EBZ1aWAz   True  False  False   True
BjHgTXcpy0  False  False   True   True
rOj7BN4mbq  False   True  False   True
ULyw3Hm61E   True  False  False   True
nlTLSnkn9g  False  False  False   True
TVqJwv23fl  False  False  False  False
4IrjoN45oG  False  False  False  False
6Q5YuWOFxa  False  False  False  False

>>> mask = (a > .5) & (a < .7)
>>> mask.sum()
A    2
B    0
C    4
D    2
dtype: int64
>>> mask.sum().sum()
8
>>> a[mask]
                   A   B         C         D
dXkJTlAkc9  0.514351 NaN       NaN       NaN
Ln09Q1q7g9       NaN NaN       NaN       NaN
dIQgDaq9b2       NaN NaN       NaN       NaN
xWFDToUkr7       NaN NaN       NaN       NaN
xH5mELuojY       NaN NaN       NaN       NaN
CjpqxkePjD       NaN NaN       NaN       NaN
xY9RGCqhAO       NaN NaN       NaN       NaN
EKnui571zS       NaN NaN       NaN       NaN
ghJrNKJuY8       NaN NaN  0.564886       NaN
H8w4cuIphV       NaN NaN  0.640341       NaN
ALxoOl1jJb       NaN NaN       NaN  0.523452
XJ4nlr8XK0       NaN NaN  0.685678       NaN
ddgrXORpkh       NaN NaN  0.611645       NaN
oOsZDhi00d       NaN NaN       NaN  0.679720
Ycer5SJX9T       NaN NaN       NaN       NaN
O3WO2G2eOv       NaN NaN       NaN       NaN
qLhZJtZuR3       NaN NaN       NaN       NaN
eiBuxfXWyM       NaN NaN       NaN       NaN
VdxcO7Gztz       NaN NaN       NaN       NaN
xoRXaQcMY8       NaN NaN       NaN       NaN
jsc3WBYqfO       NaN NaN       NaN       NaN
D3XaUA5wxS       NaN NaN       NaN       NaN
z8EBZ1aWAz       NaN NaN       NaN       NaN
BjHgTXcpy0       NaN NaN       NaN       NaN
rOj7BN4mbq       NaN NaN       NaN       NaN
ULyw3Hm61E  0.591463 NaN       NaN       NaN
nlTLSnkn9g       NaN NaN       NaN       NaN
TVqJwv23fl       NaN NaN       NaN       NaN
4IrjoN45oG       NaN NaN       NaN       NaN
6Q5YuWOFxa       NaN NaN       NaN       NaN
>>> 


2022-09-20 16:21

If you have any answers or tips


© 2022 pinfo. All rights reserved.