NameError: имя 'bo5' не определено - PullRequest
1 голос
/ 10 октября 2019

Не могу больше импортировать pandas! Я пытаюсь перенести содержимое из несортированного файла CSV в хорошо отсортированный значащий файл CSV, используя pandas в Spyder.

код работал нормально до вчерашнего дня, но больше не работает.


Ошибка при импорте панд:

runfile('C:/Users/divyanshu.e.sharma/Documents/AUTOMATION/Zabbix Report Generation/Live/Zabbix.py', wdir='C:/Users/divyanshu.e.sharma/Documents/AUTOMATION/Zabbix Report Generation/Live')
Traceback (most recent call last):

File "<ipython-input-1-a9ba60fee448>", line 1, in <module>
runfile('C:/Users/divyanshu.e.sharma/Documents/AUTOMATION/Zabbix Report Generation/Live/Zabbix.py', wdir='C:/Users/divyanshu.e.sharma/Documents/AUTOMATION/Zabbix Report Generation/Live')

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/divyanshu.e.sharma/Documents/AUTOMATION/Zabbix Report Generation/Live/Zabbix.py", line 18, in <module>
import pandas as pd

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\api.py", line 26, in <module>
from pandas.core.groupby import Grouper

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
from pandas.core.groupby.groupby import GroupBy  # noqa: F401

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 37, in <module>
from pandas.core.frame import DataFrame

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py", line 87, in <module>
from pandas.core.generic import NDFrame, _shared_docs

File "C:\Users\divyanshu.e.sharma\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py", line 1, in <module>
bo5# pylint: disable=W0231,E1101

NameError: name 'bo5' is not defined

Попытка поиска 'bo5' в коде, но не найти каких-либо случаев, чтобы идти вперед. Попытался изменить код нового каталога при воссоздании аналогичной среды. Но не помогает.

# -*- coding: utf-8 -*-
"""
Created on Fri Oct  4 20:13:23 2019
@author: divyanshu.e.sharma
"""
#! /usr/bin/python
import csv
import pandas as pd
from datetime import datetime
from dateutil import tz
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
def get_person(day,shift):
    with open(r'C:\Users\divyanshu.e.sharma\Documents\Test\Shift_Roster.csv',"r+") as shifts:
    reader1 = csv.reader(shifts, delimiter=',')
    for j in reader1:
        if str(j[0]) == str(day):
            if shift == 1:
                return j[1]
            elif shift == 2:
                return j[2]
            else:
                return j[3]
f= open(r'C:\Users\divyanshu.e.sharma\Documents\Test\MY_OUTPUT.txt',"w+")
f.truncate()
f.close()
f= open(r'C:\Users\divyanshu.e.sharma\Documents\Test\OUTPUT.csv',"w+")
f.truncate()
f.close()
with open(r'C:\Users\divyanshu.e.sharma\Documents\Test\change_request.csv',"r+") as changes:
next(changes,None)
print ('CHANGE; ENVIRONMENT; AFFECTED CIs; DATA CENTER; START TIME; END TIME; ASSIGNEE;', file=open(r'C:\Users\divyanshu.e.sharma\Documents\Test\MY_OUTPUT.txt', "w+"))
reader = csv.reader(changes, delimiter=',')
for i in reader:
    change = i[0]
    envi = i[4]
    aci = i[5]
    dc = i[7]
    start = i[9]
    end = i[10]
    utc_start = datetime.strptime(start, '%Y-%m-%d %H:%M:%S')
    utc_start = utc_start.replace(tzinfo=from_zone)
    utc_end = datetime.strptime(end, '%Y-%m-%d %H:%M:%S')
    utc_end = utc_end.replace(tzinfo=from_zone)
    ist_start = utc_start.astimezone(to_zone)
    ist_end = utc_end.astimezone(to_zone)
    start_split =  str(ist_start).split(" ")
    start_day = start_split[0].split("-")
    start_time = start_split[1][:-6].split(":")
    if int(start_time[0]) > 6 and int(start_time[0]) < 15:
        name = get_person(start_day[2],1)
    elif int(start_time[0]) > 15 and int(start_time[0]) < 23:
        name = get_person(start_day[2],2)
    else:
        name = get_person(start_day[2],3)
    {
    print (change + ";" + envi + ";" + aci + ";" + dc + ";"+ str(ist_start) + ";" + str(ist_end) + ";" + str(name), file=open(r'C:\Users\divyanshu.e.sharma\Documents\Test\MY_OUTPUT.txt', "a"))
    }
df = pd.read_csv(r'C:\Users\divyanshu.e.sharma\Documents\Test\MY_OUTPUT.txt', sep=';', header=0)
df.drop(["Unnamed: 7"], axis=1, inplace=True)
df.columns = ['CHANGE', 'ENVIRONMENT', 'AFFECTED CIs', 'DATA CENTER', 'START TIME(IST)', 'END TIME(IST)', 'ASSIGNEE']
df.sort_values("START TIME(IST)", axis=0, ascending=True, inplace=True)
df['START TIME(IST)'] = pd.to_datetime(df['START TIME(IST)'], errors='coerce')
df['END TIME(IST)'] = pd.to_datetime(df['END TIME(IST)'], errors='coerce')
dur=(df['END TIME(IST)']-df['START TIME(IST)']).astype('timedelta64[h]')
df['Duration (Hours)']=dur
df['START TIME(IST)'] = df['START TIME(IST)'].dt.strftime('%m/%d/%Y, %H:%M:%S')
df['END TIME(IST)'] = df['END TIME(IST)'].dt.strftime('%m/%d/%Y, %H:%M:%S')
columnsTitles = ['CHANGE', 'ENVIRONMENT', 'AFFECTED CIs', 'DATA CENTER', 'START TIME(IST)', 'END TIME(IST)', 'Duration (Hours)', 'ASSIGNEE']
df = df.reindex(columns=columnsTitles)
df.to_csv(r'C:\Users\divyanshu.e.sharma\Documents\Test\OUTPUT.csv', index=False)
...