df = pd.read_csv('C:/Users/bhila/Desktop/Pandas-Data-Science-Tasks-master/SalesAnalysis/Sales_Data/Sales_April_2019.csv') files = [file for file in os.listdir('C:/Users/bhila/Desktop/Pandas-Data-Science-Tasks-master/SalesAnalysis/Sales_Data')] all_months_data = pd.DataFrame() for file in files: print(file) df = pd.read_csv('C:/Users/bhila/Desktop/Pandas-Data-Science-Tasks-master/SalesAnalysis/Sales_data/'+file) all_monhts_data = pd.concat([all_months_data, df]) all_months_data.to_csv("all_data.csv", index=False)
It still won’t create a all_data.csv
file.
Advertisement
Answer
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html
According to this, 1st argument is path. From your example it will save your .csv
in the same folder in which you are running your .py
file from. If you want to change this to something else
all_months_data.to_csv("all_data.csv", index=False)
replace "all_data.csv"
to an absolute or relative path to the location you want it saved to?