본문 바로가기

python 공부2392

파이썬 Add a new sheet to a existing workbook in python 거의 모든 이전 스레드를 탐색했지만 여전히이 작업을 수행 할 수 없습니다. 기존 통합 문서에 새 시트를 추가하려고합니다. 내 코드는 작동하지만 훨씬 더 많은 (실제로 너무 많은) 시트를 계속 추가합니다. 해결책을 찾을 수 없습니다. 다음은 내 코드입니다. from openpyxl import load_workbook wb2 = load_workbook('template.xlsx') from xlutils.copy import copy as xl_copy wb = xl_copy(wb2) wb.create_sheet('sid1') wb.save('template.xlsx') 해결 방법 기존 스프레드 시트에 시트를 추가하려면 load 개체를 복사하고 새 시트를 추가하는 대신 파일에 새 시트를 추가하면됩니다. .. 2020. 10. 27.
파이썬 Represent infinity as an integer in Python 2.7 Python 2.7에서 inf 및 -inf 를 int 로 정의하는 방법이 궁금합니다. 시도했지만 inf 및 -inf 는 float 로만 작동합니다. a = float('-inf') # works b = float('inf') # works c = int('-inf') # compile error, ValueError: invalid literal for int() with base 10: 'inf' d = int('inf') # compile error, ValueError: invalid literal for int() with base 10: 'inf' 해결 방법 댓글에서 말한 내용을 요약하면 파이썬에서 무한대를 정수로 표현하는 방법은 없습니다. 이것은 다른 많은 언어의 동작과 일치합니다. 그러나 P.. 2020. 10. 27.
파이썬 Python : OverflowError : 수학 범위 오류 이 계산을 시도 할 때 오버플로 오류가 발생하지만 이유를 알 수 없습니다. 1-math.exp(-4*1000000*-0.0641515994108) 해결 방법 math.exp에 계산하도록 요청한 숫자는 10 진수로 110,000 자리가 넘습니다. double 범위를 약간 벗어 났으므로 오버플로가 발생합니다. 참조 페이지 https://stackoverflow.com/questions/4050907 2020. 10. 26.
파이썬 Python source code collection 누구든지 괜찮은 문서와 함께 인터넷에 광범위한 Python 소스 코드 모음이 있다는 것을 알고 있습니까? 그렇다면 누군가 여기에 게시 할 수 있습니까? 해결 방법 참조 페이지 https://stackoverflow.com/questions/405374 2020. 10. 26.
파이썬 Python 3에서 URL 인코딩하는 방법은 무엇입니까? from urllib.parse import urlparse params = urlparse.parse.quote_plus({'username': 'administrator', 'password': 'xyz'}) 나는 얻다 AttributeError : '함수'개체에 'parse'속성이 없습니다. 해결 방법 문서를 잘못 읽었습니다. 다음 두 가지를 수행해야합니다. 운 좋게도 urllib.parse.urlencode 는이 두 가지 작업을 한 번에 수행하며 이것이 사용해야하는 기능입니다. from urllib.parse import urlencode, quote_plus payload = {'username':'administrator', 'password':'xyz'} result = urlencode(p.. 2020. 10. 26.
파이썬 Openpyxl 인덱스로 워크 시트에서 행을 가져 오는 방법 Openpyxl 및 python3.5를 사용하여 아래 첨자를 사용하여 Excel 워크 시트에서 첫 번째 행을 가져 오려고했지만 오류가 발생했습니다. # after getting filename # after loading worksheet # to get the first row of the worksheet first_row = worksheet.rows[0] # I get Traceback (most recent call last): File "", line 1, in first_row = phc_th_sheet.rows[1] TypeError: 'generator' object is not subscriptable 첫 번째 행을 얻는 것과 관련하여 나는 또한 시도했습니다 first_row = wor.. 2020. 10. 26.
파이썬 matplotlib 막대 차트 : 공백 막대 import matplotlib.pyplot as plt import matplotlib.dates as mdates def ww(self):#wrongwords text file with open("wrongWords.txt") as file: array1 = [] array2 = [] for element in file: array1.append(element) x=array1[0] s = x.replace(')(', '),(') #removes the quote marks from csv file print(s) my_list = ast.literal_eval(s) print(my_list) my_dict = {} for item in my_list: my_dict[item[2]] = my_dict.. 2020. 10. 26.
파이썬 오류 발생-AttributeError : subprocess.run ([ "ls", "-l"])을 실행하는 동안 'module'개체에 'run'속성이 없습니다. 저는 AIX 6.1에서 실행 중이고 Python 2.7을 사용하고 있습니다. 다음 줄을 실행하고 싶지만 오류가 발생합니다. subprocess.run(["ls", "-l"]) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'run' 해결 방법 그러나 백 포트하는 것은 쉽습니다. def run(*popenargs, **kwargs): input = kwargs.pop("input", None) check = kwargs.pop("handle", False) if input is not None: if 'stdin' in kwargs: raise ValueError('s.. 2020. 10. 26.
파이썬 TypeError : 'int'개체는 구독 할 수 없습니다. 파이썬에서는이 오류가 발생합니다. TypeError: 'int' object is unsubscriptable 이것은 라인에서 발생합니다. sectorcalc[i][2]= ((today[2]/yesterday[2])-1) 나는 어디서나 파이썬에 대한 구독 불가의 좋은 정의를 찾을 수 없었습니다. for quote in sector[singlestock]: i+=1 if i < len(sector): if i==0: sectorcalc[i][0]= quote[0] sectorcalc[i][2]= 0 sectorcalc[i][3]= 0 sectorcalc[i][4]= 0 sectorcalc[i][5]= 0 sectorcalc[i][6]= 0 sectorcalc[i][7]= 0 else: yesterday =.. 2020. 10. 26.
파이썬 목록으로 Pandas 데이터 프레임 열 선택 내 스크립트 중 하나에서 열 이름 목록으로 데이터 프레임의 여러 열을 선택하고 있습니다. 다음 코드가 작동합니다. data = df[lst] 목록의 모든 요소가 데이터 프레임에 포함되어 있으면 제대로 작동합니다. 그렇지 않은 경우 " '....'not in index"오류가 반환됩니다. 목록의 모든 요소가 데이터 프레임에 포함되지 않더라도 해당 목록에 포함 된 열 이름을 모두 선택할 수있는 가능성이 있습니까? 해결 방법 df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6], 'C':[7,8,9], 'D':[1,3,5], 'E':[5,3,6], 'F':[7,4,3]}) print (df) A B C D E F 0 1 4 7 1 5 7 1 2 5 8 3 3 4 2 3 6 9 5 6 .. 2020. 10. 26.