簡體   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