Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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 如何从其他两列之间的列中获取数据帧的行?_Python_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 如何从其他两列之间的列中获取数据帧的行?

Python 如何从其他两列之间的列中获取数据帧的行?,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,我想要两个索引之间的数据帧列,endDate和totalCurrentAssets,但不包括它们。所以我尝试了.iloc: >>>ticker.balance_sheet().loc[:, 'endDate':'totalCurrentAssets'] endDate cash shortTermInvestments netReceivables inventory otherCurrentAssets totalCurrentA

我想要两个索引之间的数据帧列,
endDate
totalCurrentAssets
,但不包括它们。所以我尝试了
.iloc

>>>ticker.balance_sheet().loc[:, 'endDate':'totalCurrentAssets']

        endDate     cash    shortTermInvestments    netReceivables  inventory   otherCurrentAssets  totalCurrentAssets
symbol  row                             
MSFT    0   2019-06-30  11356000000     122476000000    29524000000     2063000000  10133000000     175552000000
1   2018-06-30  11946000000     121718000000    26481000000     2662000000  6855000000  169662000000
2   2017-06-30  7663000000  125238000000    22431000000     2181000000  5183000000  162696000000
3   2016-06-30  6510000000  106531000000    18277000000     2251000000  6091000000  139660000000
cols = df.columns
df.iloc[:, cols.get_loc('endDate')+1 : cols.get_loc('totalCurrentAssets')]

一种方法是使用
iloc
链接
loc
,以获取进一步的切片:

df.loc[:,'endDate':'totalCurrentAssets'].iloc[:,1:-1]
或者您也可以使用
索引。获取位置

>>>ticker.balance_sheet().loc[:, 'endDate':'totalCurrentAssets']

        endDate     cash    shortTermInvestments    netReceivables  inventory   otherCurrentAssets  totalCurrentAssets
symbol  row                             
MSFT    0   2019-06-30  11356000000     122476000000    29524000000     2063000000  10133000000     175552000000
1   2018-06-30  11946000000     121718000000    26481000000     2662000000  6855000000  169662000000
2   2017-06-30  7663000000  125238000000    22431000000     2181000000  5183000000  162696000000
3   2016-06-30  6510000000  106531000000    18277000000     2251000000  6091000000  139660000000
cols = df.columns
df.iloc[:, cols.get_loc('endDate')+1 : cols.get_loc('totalCurrentAssets')]

从检索相关列的整数索引(编号)开始:

n1 = df.columns.get_loc('endDate')
n2 = df.columns.get_loc('totalCurrentAssets')
然后将iloc与这些指数一起使用,分别进行校正:

df.iloc[:, n1 + 1 : n2]
将不检索此整数为n2的时间列