# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Example 1

name = '<NAME>'
name_split = name.split()
(name_split[1]+' '+name_split[0]).title()

name = '<NAME>'
name_split = name.split()
name_result = (name_split[1]+' '+name_split[0]). title()
print("Processed name: "+ name_result)

# Good introduction to python strings can be found at https://developers.google.com/edu/python/strings

# ## Exmaple 2

names = ['<NAME>', '<NAME>', '<NAME>']
for name in names:
    name_split = name.split()
    name_result = (name_split[1]+' '+name_split[0]). title()
    print("Processed name: "+ name_result)

# Similar axample but with larger number of names and with some names having the same given or last name. 

names = ['<NAME>', 
         '<NAME>', 
         '<NAME>', 
         '<NAME>', 
         '<NAME>', 
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>',
         '<NAME>']
for name in names:
    name_split = name.split()
    name_result = (name_split[1]+' '+name_split[0]). title()
    print("Processed name: "+ name_result)

# ## Example 3

import pandas

names = pandas.read_excel('./names.xlsx')

names

names['Last name'] = 'DR '+ names['Last name'].str.upper()

names['First name'] = names['First name'].str.capitalize()

names

names = names[['First name', 'Last name']]

names

# Final code put together

# +
import pandas
names = pandas.read_excel('./names.xlsx')
names['Last name'] = 'DR '+ names['Last name'].str.upper()
names['First name'] = names['First name'].str.capitalize()
names = names[['First name', 'Last name']]

writer = pandas.ExcelWriter('names_processed.xlsx')
names.to_excel(writer, 'Sheet1')
writer.close()

# -

# ## Example 4

f = open('./names.txt')
firstnames = []
lastnames  = []
for line in f.readlines():
    if line.startswith('LN'):
        lastnames.append(line.split()[1])
    elif line.startswith('FN'):
        firstnames.append(line.split()[1])
    else:
        pass
f.close()    

firstnames

lastnames

# ## Example 5

import numpy
numpy.set_printoptions(precision=3 , suppress= True) # this is just to make the output look better


numbers = numpy.loadtxt('./numpers.txt')

numbers

reshaped = numbers.reshape(3,3)
reshaped

reshaped[:,2].mean()

# Final code put together

import numpy
numbers = numpy.loadtxt('./numpers.txt')
reshaped = numbers.reshape(3,3)
reshaped[:,2].mean()









StarcoderdataJupyterScriptsDedupFiltered