python - to_excel on desktop regardless of the user -
is there way use pandas to_excel
function write desktop, no matter user running script? i've found answers vba nothing python or pandas.
pandas.dataframe.to_excel()
requires argument excel_writer
either file path or existing excelwriter-object.
just give path argument:
>>> df.to_excel('path_to_your_file.xls')
more specifically, write users desktop, use os.path.expanduser
:
>>> path = os.path.join(os.path.expanduser("~"), "desktop", "your_file.xls") >>> df.to_excel(path)
os.path.expanduser
guarantees you'll home directory of user on posix , windows there many corner cases should take account.
for example on windows, if users home directory managed via active directory, you'll home directory resides on network drive, , there might not desktop
-folder. similarily linux users have free hands rename or delete folder called desktop
. or might not have desktop
folder, linux doesn't need window manager run.
Comments
Post a Comment