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
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
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
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]