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.
import pandas as pd with open('./Essentials/test2.csv','r') as f: weather_df = pd.read_csv(f)
STAT,NAME,DATE,TA,TM,TMI test123,"ASDDD",10115,23,29,17 test123,"ASDDD",20115,23,29.2,20 test123,"ASDDD",30115,24,29.9,20 test123,"ASDDD",40115,23,26.1,13 test123,"ASDDD",50115,20,23.7,18 test123,"ASDDD",60115,20,24.3,13 test123,"ASDDD",70115,17,22.5,13 test123,"ASDDD",80115,17,22.9,12 test123,"ASDDD",90115,18,23.3,13 test123,"ASDDD",100115,19,13.2,13 test123,"ASDDD",110115,16,21,11 test123,"ASDDD",120115,19,24.5,11 test123,"ASDDD",130115,18,26.5,12 test123,"ASDDD",150115,18,28.1,13 ,"ASDDD",160115,21,28,14.2 ,"ASDDD",170115,18,24, ,"ASDDD",180115,14,16, ,,190115,14,13, ,,200115,15,18,
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
weather_df.at[row index, 'column name']
for example the following will give you a value of 17
weather_df.at[0, 'TMI']
to get the number of cells excluding NaN use .count()
weather_df.['TMI'].count()
without specifying a column it will return the non-Nan row count for each column individually