[问题] 读取dataframe中某一列某一行

楼主: jasonfghx (工人)   2018-07-02 22:08:39
https://mybox.ncku.edu.tw/navigate/s/C7780C75A59347E783561806F62FE387GSY
这是我的数据档案
简单范例我测试没问题
但是我用这个数据来测
import numpy as np
import pandas as pd
i=pd.read_csv("taipei.csv",sep=",")
i.head(3)
print (i[1,2])
执行的结果是错误
Traceback (most recent call last):
File "<ipython-input-60-a348a131c1bf>", line 1, in <module>
print (i[1,2])
File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\frame.py", line
2685, in __getitem__
return self._getitem_column(key)
File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\frame.py", line
2692, in _getitem_column
return self._get_item_cache(key)
File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\generic.py",
line 2486, in _get_item_cache
values = self._data.get(item)
File "C:\Users\user\Anaconda3\lib\site-packages\pandas\core\internals.py",
line 4115, in get
loc = self.items.get_loc(item)
File
"C:\Users\user\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line
3065, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libs\index.pyx", line 140, in
pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 162, in
pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 1492, in
pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 1500, in
pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: (1, 2)
这他讯息
实在阅读上有困难, 烦请协助感恩
请问我可以如何改善?
作者: TitanEric (泰坦)   2018-07-02 22:20:00
这个是numpy写法 应该要i.loc[0][1] 前面的方括号是rowindrx 后面的是column name或是使用i.iat[0,1] 这样两边都是index
作者: abc2090614 (casperxdd)   2018-07-03 07:18:00
用i.iloc[0,1]比较好也比较快如果只取一列就用.iat
作者: sherees (ShaunTheSheep)   2018-07-03 15:38:00
.at

Links booklink

Contact Us: admin [ a t ] ucptt.com