问题:
import csv
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("D:/data/0403/output2.csv", index_col=0,encoding='GBK')
df[:3]
代码正确,出现错误:IndexError: list index out of range
参考答案:
https://blog.csdn.net/weixin_37746009/article/details/94367162ll
关键点:
list在读取的时候下标是从0开始读取的,list在已经定义的范围内,我们可以读取到索引值对应的值,但是如果下标没有定义,那么他的值是没有办法读取到的,这个时候也就是为什么会出现IndexError: list index out of range
。
为了方便读者理解,以下代码创建参考表格
outfile = open(r"D:\data\0403\output11.csv", "w", newline="")
writer = csv.writer(outfile)
heads_transfer=['id','stat