提示用户从csv文件输入列名(不使用pandas框架) [英] Prompting user to enter column names from a csv file (not using pandas framework)

查看:68
本文介绍了提示用户从csv文件输入列名(不使用pandas框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从具有近4000行的csv文件中获取列名.大约有14列.

I am trying to get the column names from a csv file with nearly 4000 rows. There are about 14 columns.

我正在尝试获取每一列并将其存储在列表中,然后提示用户至少输入要查看的5列.

I am trying to get each column and store it into a list and then prompt the user to enter themselves at least 5 columns they want to look at.

然后,用户应该能够键入他们想看到多少个结果(它们应该是该列中最小的结果).

The user should then be able to type how many results they want to see (they should be the smallest results from that column).

例如,如果他们选择服装品牌"8",则显示8个最便宜的品牌.

For example, if they choose clothing_brand, "8", the 8 least expensive brands are displayed.

到目前为止,我已经能够使用"with"并获得包含每一列的列表,但是我很难提示用户选择至少五列.

So far, I have been able to use "with" and get a list that contains each column, but I am having trouble prompting the user to pick at least 5 of those columns.

推荐答案

如果要提示否,则可以很好地使用Python输入从用户那里获取输入.有时,请使用for循环获取输入.检查以下代码:

You can very well use the Python input to get the input from user, if you want to prompt no. of times, use the for loop to get inputs. Check Below code:

def get_user_val(no_of_entries = 5):
    print('Enter {} inputs'.format(str(no_of_entries)))
    val_list = []
    for i in range(no_of_entries):
            val_list.append(input('Enter Input {}:'.format(str(i+1))))
    return val_list

get_user_val()

这篇关于提示用户从csv文件输入列名(不使用pandas框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆