In [1]:
import pandas as pd

In [2]:
df = pd.read_csv('short_class_list.csv',index_col=0)
df


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-050cefe178aa> in <module>()
----> 1 df = pd.read_csv('short_class_list.csv',index_col=0)
      2 df

~/anaconda3/envs/pelican/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
    653                     skip_blank_lines=skip_blank_lines)
    654 
--> 655         return _read(filepath_or_buffer, kwds)
    656 
    657     parser_f.__name__ = name

~/anaconda3/envs/pelican/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    403 
    404     # Create the parser.
--> 405     parser = TextFileReader(filepath_or_buffer, **kwds)
    406 
    407     if chunksize or iterator:

~/anaconda3/envs/pelican/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
    762             self.options['has_index_names'] = kwds['has_index_names']
    763 
--> 764         self._make_engine(self.engine)
    765 
    766     def close(self):

~/anaconda3/envs/pelican/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
    983     def _make_engine(self, engine='c'):
    984         if engine == 'c':
--> 985             self._engine = CParserWrapper(self.f, **self.options)
    986         else:
    987             if engine == 'python':

~/anaconda3/envs/pelican/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   1603         kwds['allow_leading_cols'] = self.index_col is not False
   1604 
-> 1605         self._reader = parsers.TextReader(src, **kwds)
   1606 
   1607         # XXX

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__ (pandas/_libs/parsers.c:4209)()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source (pandas/_libs/parsers.c:8873)()

FileNotFoundError: File b'short_class_list.csv' does not exist

In [3]:
df2 = df.copy()
print(df2)
i=0
for row in df.itertuples():
    cn = row[1]
    print(cn)
    dept_list = [s for s in cn[0:4] if s.isalpha()]
    print(dept_list)
    dept_len = len(dept_list)
    dept = head = cn[0:dept_len]
    print('Department: '+dept)
    course_num = tail = cn[dept_len:]
    print('Course Number: '+course_num)
    df2.loc[i] = [dept, course_num]
    i = i+1


   course number                      course name
0          AB100          Auto Body Basic Skills 
1          AB117                Auto Painting II 
2          AB201               Panel Replacement 
3          AB205    Tech Skills/Collision Repair 
4         AB280A            CE: Auto Body Repair 
5         AB280B  CE: Auto Body Repair - Seminar 
6        ABE0782       ABE Foundations of Math 1 
7        ABE0790            Intermediate RD & WR 
8        ABE0790            Intermediate RD & WR 
9          AD101                       Addiction 
10         AD102          Drug Use and Addiction 
11         AD104        Multicultural Counseling 
12         AD106              Nicotine Cessation 
13         AD107       Addiction Recovery Mentor 
14         AD110      Substance Abuse Prevention 
15         AD152     Group Counsel and Addiction 
16         AD153          Theories of Counseling 
17         AD154  Client Record Mgmt & Addiction 
18         AD156   Prof Ethics Issues Counseling 
19         AD160                Basic Counseling 
20         AD161   Motivational Interview/Addict 
21         AD184                 Men & Addiction 
22         AD255              Multiple Diagnoses 
23        AD270A            Practicum: Addiction 
24        AD270B   Practicum: Addiction- Seminar 
25         AD278                  Practicum Prep 
AB100
['A', 'B']
Department: AB
Course Number: 100
AB117
['A', 'B']
Department: AB
Course Number: 117
AB201
['A', 'B']
Department: AB
Course Number: 201
AB205
['A', 'B']
Department: AB
Course Number: 205
AB280A
['A', 'B']
Department: AB
Course Number: 280A
AB280B
['A', 'B']
Department: AB
Course Number: 280B
ABE0782
['A', 'B', 'E']
Department: ABE
Course Number: 0782
ABE0790
['A', 'B', 'E']
Department: ABE
Course Number: 0790
ABE0790
['A', 'B', 'E']
Department: ABE
Course Number: 0790
AD101
['A', 'D']
Department: AD
Course Number: 101
AD102
['A', 'D']
Department: AD
Course Number: 102
AD104
['A', 'D']
Department: AD
Course Number: 104
AD106
['A', 'D']
Department: AD
Course Number: 106
AD107
['A', 'D']
Department: AD
Course Number: 107
AD110
['A', 'D']
Department: AD
Course Number: 110
AD152
['A', 'D']
Department: AD
Course Number: 152
AD153
['A', 'D']
Department: AD
Course Number: 153
AD154
['A', 'D']
Department: AD
Course Number: 154
AD156
['A', 'D']
Department: AD
Course Number: 156
AD160
['A', 'D']
Department: AD
Course Number: 160
AD161
['A', 'D']
Department: AD
Course Number: 161
AD184
['A', 'D']
Department: AD
Course Number: 184
AD255
['A', 'D']
Department: AD
Course Number: 255
AD270A
['A', 'D']
Department: AD
Course Number: 270A
AD270B
['A', 'D']
Department: AD
Course Number: 270B
AD278
['A', 'D']
Department: AD
Course Number: 278

In [4]:
cn = 'WLD286B'
cn


Out[4]:
'WLD286B'

In [5]:
df2


Out[5]:
course number course name
0 AB 100
1 AB 117
2 AB 201
3 AB 205
4 AB 280A
5 AB 280B
6 ABE 0782
7 ABE 0790
8 ABE 0790
9 AD 101
10 AD 102
11 AD 104
12 AD 106
13 AD 107
14 AD 110
15 AD 152
16 AD 153
17 AD 154
18 AD 156
19 AD 160
20 AD 161
21 AD 184
22 AD 255
23 AD 270A
24 AD 270B
25 AD 278

In [6]:
df.append(df2)


Out[6]:
course number course name
0 AB100 Auto Body Basic Skills
1 AB117 Auto Painting II
2 AB201 Panel Replacement
3 AB205 Tech Skills/Collision Repair
4 AB280A CE: Auto Body Repair
5 AB280B CE: Auto Body Repair - Seminar
6 ABE0782 ABE Foundations of Math 1
7 ABE0790 Intermediate RD & WR
8 ABE0790 Intermediate RD & WR
9 AD101 Addiction
10 AD102 Drug Use and Addiction
11 AD104 Multicultural Counseling
12 AD106 Nicotine Cessation
13 AD107 Addiction Recovery Mentor
14 AD110 Substance Abuse Prevention
15 AD152 Group Counsel and Addiction
16 AD153 Theories of Counseling
17 AD154 Client Record Mgmt & Addiction
18 AD156 Prof Ethics Issues Counseling
19 AD160 Basic Counseling
20 AD161 Motivational Interview/Addict
21 AD184 Men & Addiction
22 AD255 Multiple Diagnoses
23 AD270A Practicum: Addiction
24 AD270B Practicum: Addiction- Seminar
25 AD278 Practicum Prep
0 AB 100
1 AB 117
2 AB 201
3 AB 205
4 AB 280A
5 AB 280B
6 ABE 0782
7 ABE 0790
8 ABE 0790
9 AD 101
10 AD 102
11 AD 104
12 AD 106
13 AD 107
14 AD 110
15 AD 152
16 AD 153
17 AD 154
18 AD 156
19 AD 160
20 AD 161
21 AD 184
22 AD 255
23 AD 270A
24 AD 270B
25 AD 278

In [7]:
dept_list = [s for s in cn[0:4] if s.isalpha()]
dept_list


Out[7]:
['W', 'L', 'D']

In [8]:
dept_len = len(dept_list)

In [9]:
head = cn[0:dept_len]
head


Out[9]:
'WLD'

In [10]:
tail = cn[dept_len:]
tail


Out[10]:
'286B'

In [ ]: