引入文件:
df = pd.read_csv('账目', encoding='gbk')
营业总收入 = df['营业总收入(元)']
打印文件内容:
print(营业总收入)
打印结果
0 1.880202e+10
1 1.298680e+10
2 1.869429e+10
3 1.658547e+10
4 1.892101e+10
5 1.344230e+10
6 1.686647e+10
7 1.657467e+10
8 1.651403e+10
9 1.321172e+10
10 1.474092e+10
11 1.543451e+10
12 1.587898e+10
13 1.750274e+10
Name: 营业总收入(元), dtype: float64
打印第一个值,也没问题
print(营业总收入)[0])
18802019733.8
可是当用[-1]就报错了
print(营业总收入[-1])
报错内容
Traceback (most recent call last):
File "E:\python\lib\site-packages\pandas\core\indexes\range.py", line 351, in get_loc
return self._range.index(new_key)
ValueError: -1 is not in range
The above exception was the direct cause of the following exception:
File "E:\python\lib\site-packages\pandas\core\indexes\range.py", line 353, in get_loc
raise KeyError(key) from err
KeyError: -1
使用以下代码的话可以正常输出最后一个值, 但我记得一直都可以用[-1]直接索引的啊
print(营业总收入[len(营业总收入)-1])