简体   繁体   English

pandas - 用户选择图表的列

[英]pandas - user choose columns for graphs

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?所以我需要制作一个程序来读取 excel 文件并自动与用户选择的列制作一些比较图,但我被困在列表部分,如何让用户从列列表中选择并制作 pandas识别用户输入选择? Is there any function or library to make this easier for me?是否有任何 function 或库可以让我更轻松?

Sorry if this is a dumb question, I'm still new to this.对不起,如果这是一个愚蠢的问题,我还是新手。

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
  

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好的,所以我环顾四周,找到了用户必须在此站点中列出他想要的列的部分的解决方案: 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现在我只需要弄清楚如何使 pandas 将用户创建的 column_list 与 dataframe 列相关联并使用 plotly 来制作图表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM