Forum Discussion
How can i manage csv files from python query
- Anonymous8 years ago
Ok, thank you.
Finally i resolve with comma delimiters. Works ok:
.............................. for row in csvfiler: if row['PAIS'] != 'Total': row['TARIC'] = files[files_index]['CODPROD'] row['ACCION'] = files[files_index]['IE'] csvfilew.writerow(row) filew.close() filer.close() #Convertir a lista with open('inputData.csv', 'r') as f: filer = csv.reader(f,delimiter=';',lineterminator='\n') filelist = list(filer) f.close() with open('inputData.csv', 'w') as f: filew = csv.writer(f,delimiter=',',lineterminator='\n') filew.writerows(filelist) f.close()Thank you so much.
Regards
Álvaro
Anonymous,
I import the table into Power BI using your python script and get the following error.
I suspect the issue is caused by the special format of the CSV file, you can take a look at the following similar thread.
https://social.technet.microsoft.com/Forums/en-US/1170ca42-695c-491b-9401-4c1cefe92a7b/how-to-ignore-the-first-row-in-a-csv-import?forum=powerquery
As a workaround, I would recommend you directly connect to these csv files in Power BI Desktop, or convert the csv files to Excel in Python script, then check if the issue still persists.
Regards,
Lydia
Ok, thank you.
Finally i resolve with comma delimiters. Works ok:
..............................
for row in csvfiler:
if row['PAIS'] != 'Total':
row['TARIC'] = files[files_index]['CODPROD']
row['ACCION'] = files[files_index]['IE']
csvfilew.writerow(row)
filew.close()
filer.close()
#Convertir a lista
with open('inputData.csv', 'r') as f:
filer = csv.reader(f,delimiter=';',lineterminator='\n')
filelist = list(filer)
f.close()
with open('inputData.csv', 'w') as f:
filew = csv.writer(f,delimiter=',',lineterminator='\n')
filew.writerows(filelist)
f.close()Thank you so much.
Regards
Álvaro
- Anonymous8 years agoNot applicable
Anonymous,
Glad to hear the the issue is solved. You can accept your reply as answer as solution to close this thread.
Regards,
Lydia