I have a python script that scans some csv files from a directory, gets the last line from each, and adds them all in a new csv file. When running the script inside pycharm it runs correctly and does its designated job, but when trying to run it through a batch file (i need thath to do some automation later on) it returns an empty csv file instead of the one it's supposed to. The batch file is created by writing in a .txt file:
"path of python.exe" "path of the .py file of the script"
and then changing the .txt extension to a .bat one (that's the process i found online about creating batch files) and the script is:
import pandas as pd
import glob
import os
path = r'Path for origin files.'
r_path = r'Path of resulting file'
if os.path.exists(r_path + 'csv'):
os.remove(r_path + 'csv')
if os.path.exists(r_path + 'txt'):
os.remove(r_path + 'txt')
files = glob.glob(path)
column_list = [None] * 44
for i in range(44):
column_list[i] = str(i + 1)
df = pd.DataFrame(columns = column_list)
for name in files:
df_n = pd.read_csv(name, names = column_list)
df = df.append(df_n.iloc[-1], ignore_index=True)
del df_n
df.to_csv(r_path, index=False, header=False)
del df
What am i doing wrong?