[evad@e-vad:~]
[20:52:27] $ cat dayid.py
import pandas as pd
import csv
file1 = "/home/evad//dayid_file_1"
file2 = "/home/evad//dayid_file_2"
# example with pd bypassing validation and allowing the selection of numbered columns.
df1 = pd.read_csv(file1, header=None, delim_whitespace=True)
df2 = pd.read_csv(file2, header=None, delim_whitespace=True)
# Select column 2
print "File 1, column 2"
print df1[1]
print "File 2, column 2"
print df2[1]
# Doing a thing in csv
# This reads in the file with space as a delim, and checks that column 2 isn't
# empty. From your source data this looks like it should have a thing in it.
# Ref: https://stackoverflow.com/questions/19252588/how-do-i-test-for-null-list-entry-in-python-list
# Open the csv
with open(file1, "rb") as f:
# Set space to the delim. If you want tabs use '\t'
reader = csv.reader(f, delimiter=' ')
# Iterate over the thing
for row in reader:
try:
# Is the 3 column null/none, etc
None in row[2]
except Exception as e:
print "This field should not be empty"
[evad@e-vad:~]
[20:51:46] $ cat dayid_file_1
this is wide
that is wider
[evad@e-vad:~]
[20:51:53] $ cat dayid_file_2
thisisreallylong so whocares
thisisevenmorereallylonger so itneedstomatch
[evad@e-vad:~]
[20:53:02] $ sudo python ./dayid.py
File 1, column 2
0 is
1 is
Name: 1, dtype: object
File 2, column 2
0 so
1 so
Name: 1, dtype: object
This field should not be empty
This field should not be empty