我在txt 文件中有数据,我将其转换为数据帧(data3),我将索引重命名为从 -6 到 +5,现在,在 for 循环中,我想使用访问数据帧的特定值iloc 命令,但我没有得到正确的值。
如果我使用 data3.iloc[-6,1] 我期望返回值 = -6 但相反,我得到 -20
data3.iloc[-5,1] 我原本期待=-20,但结果却是-6
data3.iloc[-4,1] 我原以为 = -28 但结果是 -7
有人可以帮我吗?将索引保留在 -6 到 +5 之间对我来说很重要这是我的代码。谢谢
import numpy as np
import pandas as pd
data= pd.read_csv('perfilprueba.txt',delimiter=' ')
## This is because when I read the txt doesnt read dist and amp as diferent
columns
data_drop = data.drop(data.columns[[1, 2, 3, 4, 6,7]], axis=1)
data2=data_drop.rename(columns={"Unnamed: 5": "amp"})
## These are two index I will use later
m=int(round(len(data2.index)))
n=int(round(m/2))
## This is because I wanted that my data had index values from -6 to 5+ AND
## also a column with values from -6 to +5
r = pd.Series(np.linspace(-n, n-1,m))
data2['r'] = r
erre = pd.Series(np.linspace(-n, n-1,m))
data2['erre']=erre
data3=data2.set_index('r')
## Now I want to run a for loop
## that returns me the values of the "amp" column as r moves from -6 to +5
ap=[]
for r in range(-n,n):
a = data3.loc[[r],['amp']]
ap += [a]
凤凰求蛊
神不在的星期二
相关分类