I have built a program that does some data analysis and then saves it to a CSV on my desktop.
The problem is, the path for my desktop has my name in and I wont know the path of anyone else who uses it (i.e. it wont work).
Is there a way of opening a new CSV and inserting the data into it (and letting them save it), rather than the program saving it?
My code is:
import pandas as pd
import pyodbc
d=[]
key1 = raw_input('enter a keyword to search for: ')
key2 = raw_input('enter another keyword to search for: ')
conn = pyodbc.connect('DSN=QueryBuilder')
cursor = conn.cursor()
stringQ ="SELECT GrantInformation.GrantRefNumber, GrantInformation.PIName, GrantInformation.Call, GrantInformation.RoutingClassification, GrantInformation.GrantCategory, GrantInformation.AuthorisationDate, GrantInformation.HoldingOrganisationName, GrantInformation.StatusGeneral, GrantInformation.GrantTitle, GrantSummary.Summary, GrantDates.ActualStartDate, GrantDates.ActualEndDate, GrantInformation.TotalGrantValue FROM (GrantInformation LEFT JOIN GrantSummary ON GrantInformation.GrantRefNumber = GrantSummary.GrantRefNumber) LEFT JOIN GrantDates ON GrantInformation.GrantRefNumber = GrantDates.GrantRefNumber WHERE (((GrantInformation.AuthorisationDate)>='2005/4/1') AND ((GrantInformation.StatusGeneral) Like '%auth%') AND ((GrantInformation.GrantTitle) Like '%{}%'AND (GrantInformation.TransferInd)= 'false' OR (GrantInformation.GrantTitle) Like '%{}%') AND ((GrantInformation.TransferInd)= 'false')) OR (((GrantInformation.AuthorisationDate)>='2005/4/1') AND ((GrantInformation.StatusGeneral) Like '%auth%') AND ((GrantSummary.Summary) Like '%{}%'AND (GrantInformation.TransferInd)= 'false' OR (GrantSummary.Summary) Like '%{}%' AND (GrantInformation.TransferInd)= 'false'));".format(key1,key2,key1,key2)
cursor.execute(stringQ)
rows = cursor.fetchall()
for row in rows:
d.append({'GrantRefNumber':row[0],'Call':row[2],'Classification':row[3],'Grant Category':row[4],'Authorisation Date':row[5],'Organisation':row[6],'Status General':row[7],'Grant Title':row[8],'Summary':row[9],'Start Date':row[10],'End Date':row[11],'Total Value':row[12]})
df = pd.DataFrame(d)
new_df = df[['GrantRefNumber','Grant Title','Organisation','Call','Grant Category','Authorisation Date','Status General','Total Value','Classification','Start Date','End Date','Summary']]
new_df.to_csv("C:/Users/nicholas/Desktop/data.csv", header=True, index=False, encoding='utf-8')