-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-1 Python.py
111 lines (60 loc) · 1.91 KB
/
1-1 Python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
type(x) # type of variable
#bool
#false == none, 0, empty
#string
'{0} is {1} message'.format('this', 'is')
# int, float, long - big numbers in scientific notation
#list
list = [1,2,3,4]
list.pop() #takes off last element
del list[0] #remove 1 in the list
#tuple
#immutable, meaning operations create a new list, not modify old one
#useful for mantaining structure, like coordinates
#lists are more flexible, but if you want structure then use tuple
#sets
{1,2,3}
set([1,2,3])
#list without order
x & y #intersection
x | y #union
x - y #difference
#dictionary
dicts.key()
dicts.values()
dicts.get('non-existant key') #won't return an error message, avoiding error messages
#python reads up-down, but control statements make it into a tree instead of linear
for i in range(10):
print 'filler'
else:
print 'terminating message after loop is finished'
# same with while
?????
try:
1/0
except DivisionError:
print 'no dividing by zero'
#defaultdict
?????
import collections
numbers = [1,2,3,4,5,6]
defaultdict = numbers.defaultdict(int)
#csv seperators: , ; /t /n |
with open('path' , 'rU') as localfilename: #U for universal newlines ???
pass
for line in localfilename
#process
#now closed
inputFile = open('path', 'r+')
inputFile.close()
#python only points to the file, doesn't load the entire file into python
strip('|') # string into list, seperated by delimiter
rstrip() #gets rid of spaces on the right, or wtv input you enter
iteritems() #iterates through object, just like items() but different space/time vs. acessing tradeoff
#pandas and csv packages are smarter with csv delimiters (like if you had , in entries)
import csv
inputReader = csv.reader(inputFile) # automatically coverts lines into lists
import pandas as pd
df = pd.read_csv('file/path')
df['column']
pd[0:10]