weixin_43844798
2021-08-05 15:50
采纳率: 78.6%
浏览 27
已结题

报错data_weather[i][7] = data_weather[i][0].split(' ')[1] IndexError: list index out of range


import numpy as np
import pandas as pd


data1 = pd.read_csv('result.txt',sep='\t')
data2 = pd.read_csv('日.csv', encoding = 'gbk')
data_weather = pd.read_excel('天气表.xlsx')
data_weather = pd.DataFrame(data_weather)
data1 = pd.DataFrame(data1)
data2 = pd.DataFrame(data2)
data1 = data1['用气量'].groupby(data1['日期']).sum().reset_index()
data2 = data1['用气量'].groupby(data2['日期']).sum().reset_index()
data_weather = np.array(data_weather)

for i in range(data_weather.shape[0]):
        data_weather[i][7] = data_weather[i][0].split(' ')[1]
        data_weather[i][0] = data_weather[i][0].split(' ')[0]

print(data_weather)
  • 收藏

1条回答 默认 最新

  • 吃肉的小馒头 2021-08-05 16:24
    已采纳

    data_weather[i][0].split(' ') 之后的数据可能只有一个元素 取不到索引[1],可以打印看看前面split之后的数据是怎样

    打赏 评论

相关推荐 更多相似问题