본문 바로가기

Python

(69)
SWIFT 기초] 배열 슬라이싱 python과 swift 비교 >>> l = list(range(10)) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[:3] [0, 1, 2] >>> l[3:7] [3, 4, 5, 6] >>> l[7:] [7, 8, 9] 위와 같은 파이썬에서의 슬라이싱을 swift 에서는 다음과 같이 할 수 있다. 39> let l = Array(0.. l[0.. l[3.. Array(l[7...]) $R25: [Int] = 3 values { [0] = 7 [1] = 8 [2] = 9 } 43> l[7..
[EP0062] 같은 숫자로 이루어진 세제곱이 다섯개 #!/usr/bin/env python # Project Euler 62 # http://projecteuler.net/index.php?section=problems&id=62 # Problem 62 # # The cube, 41063625 (3453), can be permuted to produce two other cubes: # 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest # cube which has exactly three permutations of its digits which are also # cube. # # Find the smallest cube for which exactly five permut..
[Python초보] ValueError: invalid literal for int() with base 10: '' invalid literal for int() with base 10: '' 10진수 int() 로 변환할 수 없는 문자열: '' 이라는 뜻입니다. 한번 이 에러를 만들어 봅시다. >>> num = int("1000") >>> num 1000 "1000" 이라는 문자열을 숫자형으로 변환하여 num 이란 변수에 넣는 코드입니다. "1000"이라는 문자열은 정수를 나타내는 문자열이기 때문에, 문제없이 변환됩니다. >>> s = "abc" >>> num = int(s) Traceback (most recent call last): File "", line 1, in num = int(s) ValueError: invalid literal for int() with base 10: 'abc' "abc" 라는 문..
Geopy AttributeError: 'NoneType' object has no attribute 'latitude' 주소에서 위도와 경도를 가져오기 위해 geopy를 이용하는 코드에서 no attribute 'latitude' 에러가 발생할 수 있다. 코드를 보자. from geopy.geocoders import Nominatim def geocoding(address): geolocoder = Nominatim(user_agent="South Korea", timeout=None) geo = geolocoder.geocode(address) x_y = [geo.latitude, geo.longitude] return x_y for addr in ["강원 강릉시 해안로 1459", "강원 강릉시 초당순두부길 77번길 15"]: print(addr, geocoding(addr)) geocoding 함수는 사람들이 사용..
pandas ValueError: If using all scalar values, you must pass an index pandas 로 간단한 데이터프레임을 만들려고 했다. 코드는 다음과 같다. import pandas as pd df = pd.DataFrame({"name":"강수연", "sex":"F"}) 너무 간단한 코드이다. 데이터프레임 생성인자로 사전형식으로 데이터를 만들어 넘겼다. 아래와 같은 에러가 발생한다. Traceback (most recent call last): File "", line 1, in df = pd.DataFrame({"name":"강수연", "sex":"F"}) File "C:\PROGRAMS\Python3864\lib\site-packages\pandas\core\frame.py", line 614, in __init__ mgr = dict_to_mgr(data, index, colu..
tksheet 으로 csv 파일 내용을 tkinter 창에서 보여주기 tksheet 이라는 패키지가 있다. tkinter 기반의 GUI 프로그래밍을 할 때에, table 형식의 데이터, 즉, pandas dataframe 형식의 데이터를 보여주는 위젯을 사용할 수 있다. tksheet github 에 있는 예제를 거의 그대로 가져와서 csv 파일을 읽어 보여주는 코드를 만들어 봤다. from tksheet import Sheet import tkinter as tk import pandas as pd class demo(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.frame = tk.Fra..
파이썬 지수 수치계산방식에 따른 차이 """ calculate 50000 / n \ | 10 - 1 | | ------------ | | n | \ 10 / """ import math def f(n): return ((10 ** n - 1) / (10 ** n)) ** 50000 def f2(n): return (1 - 10 ** (-n)) ** 50000 def f_exp10_log10(n): exponent = 50000 * (math.log10(10 ** n - 1) - n) return 10 ** exponent def f_exp2_log2(n): exponent = 50000 * (math.log2(10 ** n - 1) - n * math.log2(10)) return 2 ** exponent def f_exp_ln(n): ex..
[PYTHON|SO번역] pip search 실행시에 XMLRPC API is currently disabled due to unmanageable load 에러 발생 https://stackoverflow.com/questions/66375972/getting-error-with-pip-search-and-pip-install Getting error with pip search and pip install hi it is about two days I am getting this error: ERROR: XMLRPC request failed [code:-32500] RuntimeError: PyPI's XMLRPC API is currently disabled due to unmanageable load and will be deprecated in ... stackoverflow.com 패키지를 검색하는 pip search 명령을 실행하면 에러가 발생하고 있다...