Home > Net >  wont create a csv file
wont create a csv file

Time:03-08

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.

CodePudding user response:

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?

CodePudding user response:

If you did not get any errors, the csv file must have been created and stored in the location from where your python script is executing. If you try:

import os
print(os.listdir())

you might be able to see the file present in that dir

  • Related