Reputation: 73
I am writing a function in AWS lambda to extract monthly unemployment data from some Spanish cities. The code when I try it in local works perfectly, but when I do it in lambda, I get that error. The only difference is that in local I use Python 3.7 and in lambda I have Python 3.6 (I had to do it this way to make it compatible with some modules that I included in the development package. After some research, it seems that the error comes from mixing operators and strings, but I can't think of another way to express it as I need to, and I emphasize that in local it works perfectly.
Specifically, the line of code that gives this error is:
data5.to_csv("s3://xxx/xxx/ '+ str(i).split("/")[-1] + str(fecha) + '.csv'")
I have to express it this way because I need you to save every csv with the name of the city and the date of the last updated data. The complete code to understand why I have expressed it this way is this one.
Row_list=[]
MUNICIPIOS = ['https://datosmacro.expansion.com/paro/espana/municipios/andalucia/cadiz/cadiz', 'https://datosmacro.expansion.com/paro/espana/municipios/la-rioja/la-rioja/agoncillo', 'https://datosmacro.expansion.com/paro/espana/municipios/castilla-leon/leon/bembibre']
for i in MUNICIPIOS:
data5 = pd.read_html(i, header = 0, decimal=',', thousands='.')
data5 = data5[0]
data5 = data5[["Fecha", "Tasa de Paro Registrado", "Nº de parados registrados", "Población"]]
for index, rows in data5.iterrows():
my_list =[rows.Fecha]
Row_list.append(my_list)
fecha=[Row_list[0]]
data5.to_csv("s3://xxx/xxx/ '+ str(i).split("/")[-1] + str(fecha) + '.csv'")
Can you think of a way to fix it? I haven't been able to fix it in a while. Thank you very much in advance!
Upvotes: 0
Views: 872
Reputation: 556
Your problem is mismatched quotes. Replace the line of code that gives you an error with this:
data5.to_csv("s3://xxx/xxx/ "+ str(i).split("/")[-1] + str(fecha) + ".csv")
It is important that you close strings with the same type of quote you opened them with.
Upvotes: 2