Py学习  »  Python

让python打印出我的csv中两个数字之间的行

Lilly Mayo-099 • 3 年前 • 1405 次点击  

我现在有一个代码,可以根据用户输入从csv打印出数据行,该代码显示如下:

#allows user input to select a column and then select a value from that 

    column data = pd.read_csv('/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/Locations.csv')
   rowcol = 0 #the colum that is being searched is column 0 row1 =
    int(input("Enter Number: ")) #enter in your first point on the map Eg
    15 row2 = int(input("Enter Number: ")) #enter in your 2nd point on the
    graph eg 18 result = data.iloc[[row1, row2]]

但现在我希望我的代码也打印出这两个输入值之间的行(例如,如果用户输入12和15,它会打印出12、13、14和15的行)

这就是我目前拥有的,但我不确定如何进一步:

num_list = []
for i in range(row1+1, row2):
    num_list.append(i)
    
print(f'Numbers between 2 points are:\n{btwpoints}')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129081
 
1405 次点击  
文章 [ 2 ]  |  最新文章 3 年前