When I run the specified code I get the specified Error message.
Code:
import tkinter
import csv
import pandas as pd
from tkinter import Tk
from tkinter.filedialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
df1 = pd.read_csv(filename)
df2 = df1.query("STATE != 'NY'") # stores records not in NY
df3 = df1[df1["FIRST_NAME"].str.contains(" ", regex=True)] # stores records that have a space in the first name
dferror = [df2, df3]
dferror = pd.concat(dferror).drop_duplicates().reset_index() # merges dataframes, drops duplicates
dferror.to_csv('C:\Errors.csv', index=False)
Error:
Traceback (most recent call last):
File "C:/Work/Python/EDI/NYColonial.py", line 23, in <module>
dferror.to_csv('C:\Errors.csv', index=False)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pandas\core\frame.py", line 1745, in to_csv
formatter.save()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pandas\io\formats\csvs.py", line 156, in save
compression=self.compression)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pandas\io\common.py", line 400, in _get_handle
f = open(path_or_buf, mode, encoding=encoding)
OSError: [Errno 22] Invalid argument: 'C:\\Errors.csv'
Process finished with exit code 1
If I removed the C:\
from C:\Errors.csv
it will output my csv file where my python script is located, which is not what I want it to do.
I want to be able to tell my script to output the Errors.csv file to a specific location.
How do I specify that absolute file path? I've done some research but haven't been able to find my answer.