Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pandas read.excel读取单个列中的值_Python_Excel_Pandas - Fatal编程技术网

Python 使用pandas read.excel读取单个列中的值

Python 使用pandas read.excel读取单个列中的值,python,excel,pandas,Python,Excel,Pandas,我想将excel工作表(检查图像)中的观察列表列存储到一个变量中,并在代码中迭代该变量 我编写的代码示例如下: import pandas as pd excel_file = 'file path.xlsx' watchlist = pd.read_excel(excel_file, sheet_name = 'Input_Options', usecols = 'A') print(watchlist) 但我得到的结果如下: Watchlist 0 NIFTY 1 B

我想将excel工作表(检查图像)中的观察列表列存储到一个变量中,并在代码中迭代该变量

我编写的代码示例如下:

import pandas as pd
excel_file = 'file path.xlsx'

watchlist = pd.read_excel(excel_file, sheet_name = 'Input_Options', usecols = 'A')
print(watchlist)
但我得到的结果如下:

   Watchlist
0      NIFTY
1  BANKNIFTY
2    NIFTYIT
3        NaN
4        NaN
5        NaN
6        NaN
7        NaN

我只想删除这些NaN行,因为我的监视列表中只有很少的脚本。我该怎么做??稍后我可能会在我的表中添加新脚本,但现在我只希望将这3个值存储在我的
watchlist
变量中。

我使用了
watchlist=watchlist.dropna()
,但仍然不确定为什么我首先会得到那些NaN值。

好吧,在检查了您的回复后,我成功地做到了这一点得到了我想要的结果,但现在真正的问题是为什么它首先显示那些NaN值??您的最后一行是9,这就是为什么。
Lst=[]
for v in watchlist['Watchlist'].values:
    if v==v:
       Lst.append(v)
print (Lst)