python, pandas read from csv file.
How do I get only TMI value from a specific row?
I mean by using ROW and single INDEX or COLUMN,
Like only get TMI 17 or 20 value and see how many TMI is there and get TMI line count.
JavaScript
x
4
1
import pandas as pd
2
with open('./Essentials/test2.csv','r') as f:
3
weather_df = pd.read_csv(f)
4
JavaScript
1
21
21
1
STAT,NAME,DATE,TA,TM,TMI
2
test123,"ASDDD",10115,23,29,17
3
test123,"ASDDD",20115,23,29.2,20
4
test123,"ASDDD",30115,24,29.9,20
5
test123,"ASDDD",40115,23,26.1,13
6
test123,"ASDDD",50115,20,23.7,18
7
test123,"ASDDD",60115,20,24.3,13
8
test123,"ASDDD",70115,17,22.5,13
9
test123,"ASDDD",80115,17,22.9,12
10
test123,"ASDDD",90115,18,23.3,13
11
test123,"ASDDD",100115,19,13.2,13
12
test123,"ASDDD",110115,16,21,11
13
test123,"ASDDD",120115,19,24.5,11
14
test123,"ASDDD",130115,18,26.5,12
15
test123,"ASDDD",150115,18,28.1,13
16
,"ASDDD",160115,21,28,14.2
17
,"ASDDD",170115,18,24,
18
,"ASDDD",180115,14,16,
19
,,190115,14,13,
20
,,200115,15,18,
21
csv file, here I want to get, STAT has 14 rows or NAME has 17 lines, Then call the Value, suppose call “TMI” line 8 value and put it into variable
Advertisement
Answer
to get a value of a specific cell
JavaScript
1
2
1
weather_df.at[row index, 'column name']
2
for example the following will give you a value of 17
JavaScript
1
2
1
weather_df.at[0, 'TMI']
2
to get the number of cells excluding NaN use .count()
JavaScript
1
2
1
weather_df.['TMI'].count()
2
without specifying a column it will return the non-Nan row count for each column individually