-2

Currently lets say I have 5 CSV files.

***File_A, File_B, File_C, File_D, File_E

They are filled with data in the same format

Column = Date, High, Low, Close

dunber123
  • 1
  • 2

2 Answers2

1

If your problem is how to read the chosen option and you know which files can be opened, I think this code might help you:

import pandas as pd

# List the possible files
files = ["fileA.csv", "fileB.csv", "fileC.csv"]

choose = 'z'
# Make a array with the options in the same order as the file array above
options = ['A', 'B', 'C']

# Ask the file to user until get a valid file
while choose not in options:
    choose = input("Choose one file (A, B or C): ")
    if choose not in options:
        print("No file {}. Try again!".format(choose))

df = pd.read_csv(files[options.index(choose)])
# Then do want you want if this data frame
gprearo
  • 11
  • 4
0

I'm not sure if I understood your question. But see this code:

from glob import glob

files_csv = glob('*.csv')
if len(files_csv)==0:
    input("\n I can't find any csv file.")
elif len(files_csv)==1:
    file_csv = files_csv[0]
else:
    text = 'Choose file:\n\n'
    for i,a in enumerate(files_csv):
        text += '  {}) {}\n'.format(i+1, a)
    text +='\n--> '
    file_csv = files_csv[int(input(text))-1]
Hugo Salvador
  • 1,094
  • 1
  • 11
  • 11
  • Hi! So this works, but I need it to where the user can say something like this "Please Choose Which File to Open: " user says " File_1" Then the file will open and extract the data needed for instance I need the highest number in column high and lowest number in column low. – dunber123 Nov 08 '19 at 17:38
  • You can try the functions max [1] and min[2] [1]https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.max.html [2]https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.min.html#pandas.DataFrame.min – Hugo Salvador Nov 11 '19 at 16:39