In [1]:
import csv
import pprint
In [2]:
with open('data/src/sample.csv') as f:
print(f.read())
In [3]:
with open('data/src/sample.csv') as f:
reader = csv.reader(f)
for row in reader:
print(row)
In [4]:
with open('data/src/sample.csv') as f:
reader = csv.reader(f)
l = [row for row in reader]
In [5]:
print(l)
In [6]:
print(l[1])
In [7]:
print(l[1][1])
In [8]:
l_T = [list(x) for x in zip(*l)]
print(l_T)
In [9]:
print(l_T[1])
In [10]:
print(l[0][0])
In [11]:
print(type(l[0][0]))
In [12]:
r = l[0]
print(r)
In [13]:
print([int(v) for v in r])
In [14]:
print([[int(v) for v in row] for row in l])
In [15]:
with open('data/src/sample.csv') as f:
reader = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
l_f = [row for row in reader]
In [16]:
print(l_f)
In [17]:
print(l_f[0][0])
In [18]:
print(type(l_f[0][0]))
In [19]:
with open('data/src/sample.txt') as f:
print(f.read())
In [20]:
with open('data/src/sample.txt') as f:
reader = csv.reader(f, delimiter=' ')
l = [row for row in reader]
In [21]:
print(l)
In [22]:
with open('data/src/sample_quote.csv') as f:
print(f.read())
In [23]:
with open('data/src/sample_quote.csv') as f:
reader = csv.reader(f)
for row in reader:
print(row)
In [24]:
with open('data/src/sample_quote.csv') as f:
reader = csv.reader(f, quoting=csv.QUOTE_NONE)
for row in reader:
print(row)
In [25]:
with open('data/src/sample_linebreak.csv') as f:
print(f.read())
In [26]:
with open('data/src/sample_linebreak.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
print(row)
In [27]:
with open('data/src/sample_header_index.csv') as f:
print(f.read())
In [28]:
with open('data/src/sample_header_index.csv') as f:
reader = csv.reader(f)
l = [row for row in reader]
In [29]:
pprint.pprint(l)
In [30]:
print([row[1:] for row in l[1:]])
In [31]:
print([[int(v) for v in row[1:]] for row in l[1:]])