0

So I need to make a program that reads an excel file and auto makes some comparative graphs with the columns the user choose, but I'm stuck on the list part, how can I make the user choose from the list of columns and make pandas recognize the user input choices? Is there any function or library to make this easier for me?

This is my code for now:

import pandas as pd
import os
import sys

def choose_file():
  global filepath
  filepath = input('Enter filepath: ')   
  assert os.path.exists(filepath), "I did not find the file at, " + str(filepath) #checks if file exists
  f = open(filepath, 'r+')
  print("We found your file.")
  f.close()

def open_file():
  global archive
  archive = pd.read_csv(filepath, encoding='latin1')  #pandas dataframe
  print(archive)

def choose_columns():
  print(archive.columns)
  #I'm stuck here and I don't know what to do
  
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Moon
  • 305
  • 1
  • 2
  • 11
  • 1
    Does this help? : [Get a list of numbers as input from the user](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user) – anky Apr 13 '21 at 14:32
  • I'll give it a try – Moon Apr 13 '21 at 14:36

1 Answers1

0

ok, so I looked around and found the solution to the part where the user has to list the columns he wants in this site: https://medium.com/thebit/lists-booleans-user-input-how-to-create-a-grocery-list-in-python-44454eba58df

def choose_columns():
  column_list = []
  print(archive.columns)
  needs_items = True
  while needs_items == True:
      user_input = input('Select the columns ')
      column_list.append(user_input)
      for user_input in column_list:
          print('- ' + user_input)
      answer = input("Add another item? (y/n)  ")
      if answer == "n":
          needs_items = False
          print('Your final list: ', column_list)

Now I only need to figure out how to make pandas associate the column_list created by the user with the dataframe columns and use plotly to make the graphs

Moon
  • 305
  • 1
  • 2
  • 11