Suppose I have a column with mixture of integer and float, I need to run a loop through that column to check if all values are numeric. Values that aren't numeric, dump the index of that cell in a blank list.
A column like this:
DESCRIPTION RATE
79th St & Private Dr - 5022 W 1.5
79th St & Allison Ave 1.5
Allison Ave & 81st St 1
81st St & Norfolk St 1
Norfolk St & Private Dr - 8178 N 1
Norfolk St & 84th St 1
Moller Rd & 86th St 1.5
Zionsville Rd & 86th St 1.5
I wrote a code like this but the newlist loop isn't working.
import pandas as pd
import numpy as np
df = pd.read_csv("C:\\Python34\\python scripts\\BNSF\\data\\data.csv") #read csv
col=df.columns #read header
print(col)
r=df.shape[0] #gives number of row count
c=df.shape[1] #gives number of col count
print(r, c)
typ=df.dtypes
print(typ)
newlist=[] #creates blank list
for i in range(r,1):
if df.iloc[i,1].dtype == np.int64:
pass
else:
print(df.iloc[i,1])
newlist.append(df.iloc[i,1])
print(newlist)
Need changes inside that loop. Please help.