我试图结束代码,但我有问题,如何切片 Dataframe 的基础上,用户的输入。有没有任何选项,这样做没有Pandas?
def dataSet_read():
enter = input('Enter file path:')
csvreader = csv.reader(open(enter))
head_inp = input('Has the file headers? Select Y or N:\n').upper()
header = []
if head_inp == 'Y':
header = next(csvreader)
print('\nFile headers:\n\n', header)
elif head_inp == 'N':
print("'\nFile doesn't have headers")
else:
print('Incorrect selection!!!')
sys.exit()
with open(str(enter), "r") as csvfile:
reader_variable = csv.reader(csvfile, delimiter = ",")
rows_inp = input("\nPlease provide range which you'd like to see using ',', otherwise all dataframe will open all dataset.\n")
if rows_inp == '':
for row in reader_variable:
print(row)
else:
print("????")
2条答案
按热度按时间mfuanj7w1#
将其转换为list,然后就可以像在普通的列表结构中那样进行切片。
7cjasjjr2#
我找到了得到我所需要的东西的方法,也许这不是最好的方法,但很有效:)