-1

When I run my code I get a contains

<class 'str'>
GRV-DAL-7777-05/28/2019_23:03:55-PT01
GRV-DAL-7777-05/28/2019_23:03:55-PT01
but expect
a contains  <class 'str'>
GRV-DAL-7777-05/28/2019_23:03:55-PT01
DAL-7777-05/28/2019_23:03:55-PT01

What am i missing? How is it that when I run list b through my function information a is still passing through? I feel like this is a basic python thing I don't understand.

I've saved it to multiple different list names.

import pandas as pd

#Import data from spread sheet
info = pd.read_csv('information.csv', delimiter = ',')
info['Data1'] #as a series
a =info['Data1'].values #as a numpy array
a.tolist()

print("a contains ", type(a[1]))
#
#Put data into a list
#for each item in the list 

x = []
y = []
#j is a junk list to throw away
j = []

b = []
c = []




def remove_head_of_string(g, h, t, p):
    #g is list to iterate over #h is list name to save the heads to
    #t is list name to save tails to # p is location to partition
    for i in g:     
        head, sep, tail = a[1].partition(p)
        h.append(head)
        t.append(tail)

remove_head_of_string(a, x, b, "-")
remove_head_of_string(b, j, c, "-")


#print(b)
print(b[0])
print(c[0])

I expect: a contains

<class 'str'>
GRV-DAL-7777-05/28/2019_23:03:55-PT01
DAL-7777-05/28/2019_23:03:55-PT01

but instead I'm getting: a contains

<class 'str'>
GRV-DAL-7777-05/28/2019_23:03:55-PT01
GRV-DAL-7777-05/28/2019_23:03:55-PT01
Rakesh
  • 81,458
  • 17
  • 76
  • 113

1 Answers1

2

So it looks like you are specifically using the variable 'a' in your loop instead of the value you are trying to pass in.

for i in g:     
    head, sep, tail = a[1].partition(p)  # <--- a on this line
    h.append(head)
    t.append(tail)

I suspect you meant to do:

for i in g:
    head, sep, tail = i[1].partition(p) # <--- i on this line
    h.append(head)
    t.append(tail)
Rashid 'Lee' Ibrahim
  • 1,357
  • 1
  • 9
  • 21