import os
cwd = os.getcwd()
df.to_csv(cwd+ "/BA_reviews.csv")
I didn't understand this code properly. Can someone help?
import os
cwd = os.getcwd()
df.to_csv(cwd+ "/BA_reviews.csv")
I didn't understand this code properly. Can someone help?
On
import os
# os.getcwd() is a method in os module which gives the current directory
cwd = os.getcwd
# df is dataframe and to_csv is saving the df data in csv file
#here file name is BA_reviews.csv
# you are basically concaneting the path and the filename
df.to_csv(cwd+"/BA_reviews.csv")
On
Tha's just getting the absolute path of the current folder in order to save, from the pandas dataframe, a cvs file into that folder. You can either do the same using the built-in library specific for path operations, pathlib, and f-strings, in a more pythonic way:
import pathlib
cwd = pathlib.Path().absolute()
df.to_csv(f"{cwd}/BA_reviews.csv")
os.getcwddocsso
means read
BA_reviews.csvfrom current working directory.