繁体   English   中英

pandas - 用户选择图表的列

[英]pandas - user choose columns for graphs

所以我需要制作一个程序来读取 excel 文件并自动与用户选择的列制作一些比较图,但我被困在列表部分,如何让用户从列列表中选择并制作 pandas识别用户输入选择? 是否有任何 function 或库可以让我更轻松?

对不起,如果这是一个愚蠢的问题,我还是新手。

这是我现在的代码:

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
  

好的,所以我环顾四周,找到了用户必须在此站点中列出他想要的列的部分的解决方案: 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)

现在我只需要弄清楚如何使 pandas 将用户创建的 column_list 与 dataframe 列相关联并使用 plotly 来制作图表

暂无
暂无

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

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