2

I'm building a tool for the company where I work and I've built a program that returns different statistics from any csv file, of course with an specific data structure. Now, my issue is that I don't know how to do is to request the user to upload a file. In order to create this program I've been using as practice mode,

this: df = pd.read_csv('',delimiter=';', encoding='ISO-8859-1')

Any ideas?

Tenusha Guruge
  • 2,147
  • 3
  • 18
  • 38
pyseo
  • 431
  • 1
  • 6
  • 11
  • how do you run it ? In console/terminal? In some GUI ? In Jupyter notebook ? As web page ? They need different method to get path to file or url. If you run in console/terminal then you have `filename = input()` – furas Jul 05 '19 at 03:19
  • hello Nico welcome to SO. If you're looking for a GUI, go here: https://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog – zero Jul 05 '19 at 04:02

1 Answers1

0

If you need some basic ui that the user can interact so they can select a file, you may want to consider the easygui module.

Or if you don't want to install a new module, just use tkinter built in.

Try this:

from tkinter import *
frome tkinter.filedialog import askopenfilename
import pandas as pd

Tk().withdraw()
print("Please select a csv file to load") 
file = askopenfilename()
df = pd.read_csv(file, header = 0)

Hope this helps :)) . Check out the easygui module too. The documentation is brief so you can get a hang of it after a few tries.

Joe
  • 879
  • 2
  • 6
  • 15