I have a code that accesses a CSV file through a function. I created a second function to change the name of the column header (changeName) and to not have to call it several times changing the parameters of "columnIngles" and "columnPortugues" - a call for each column -, I created a support function ( changeNameName) that takes the keys and values from a dictionary and passes as an argument in the main function call (changeName).
That is, it is a function that calls another function using the keys and values of a dictionary as parameters.
It happens that it gives the error "TypeError: unhashable type: 'dict_keys'" and I can not solve it, I tried to convert to list and frozenset but it was unsuccessful.
Any ideas how to solve it?
CSV access script:
import unicodecsv
def lerCsv(arquivo):
with open(arquivo, 'rb') as dados:
dicionario = unicodecsv.DictReader(dados)
return list(dicionario)
envolvimentoDiario = lerCsv('envolvimento_diario.csv')
Script with functions to change the keys of the columns:
envolvimentoNomesColunas = {'acct': 'id_conta', 'utc_date': 'data'}
chaves = envolvimentoNomesColunas.keys()
valores = envolvimentoNomesColunas.values()
def alterarNomeSuporte(arquivo):
for coluna in arquivo:
alterarNome(arquivo, chaves, valores)
def alterarNome(arquivo, colunaIngles, colunaPortugues):
for coluna in arquivo:
coluna[colunaPortugues] = coluna[colunaIngles] (colunaPortugues) cujos valores são iguais ao da colunaIngles
del[coluna[colunaIngles]]
alterarNomeSuporte(envolvimentoDiario)
print (envolvimentoDiario[0])
Thank you!