为什么我的代码 运行 是同一个列表,即使它甚至没有被使用?

Why is my code running the same list through even though its not even being used?

当我 运行 我的代码时,我得到一个包含

<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

我错过了什么?怎么当我运行 list b 通过我的函数信息a 还在通过?我觉得这是我不明白的基本 python 东西。

我已经将它保存到多个不同的列表名称中。

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])

我预计: 一个包含

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

但我得到的是: 一个包含

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

所以看起来您在循环中专门使用变量 'a' 而不是您尝试传入的值。

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

我怀疑你是故意的:

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