본문 바로가기

파이썬2271

파이썬 scikit-learn에서 CountVectorizer를 사용하여 토큰을 추출하는 데 사용되지 않은 문서의 빈도를 계산할 수 있습니까? scikit-learn에서 CountVectorizer 클래스로 작업했습니다. 아래 표시된 방식으로 사용하면 최종 출력이 기능 또는 토큰 수를 포함하는 배열로 구성된다는 것을 이해합니다. 이러한 토큰은 키워드 세트에서 추출됩니다. tags = [ "python, tools", "linux, tools, ubuntu", "distributed systems, linux, networking, tools", ] 다음 단계는 다음과 같습니다. from sklearn.feature_extraction.text import CountVectorizer vec = CountVectorizer(tokenizer=tokenize) data = vec.fit_transform(tags).toarray() print da.. 2020. 12. 16.
파이썬 시간과 분 단위로 두 열 간의 Pandas DataFrame 시간 차이 계산 데이터 프레임에 fromdate 및 todate 라는 두 개의 열이 있습니다. import pandas as pd data = {'todate': [pd.Timestamp('2014-01-24 13:03:12.050000'), pd.Timestamp('2014-01-27 11:57:18.240000'), pd.Timestamp('2014-01-23 10:07:47.660000')], 'fromdate': [pd.Timestamp('2014-01-26 23:41:21.870000'), pd.Timestamp('2014-01-27 15:38:22.540000'), pd.Timestamp('2014-01-23 18:50:41.420000')]} df = pd.DataFrame(data) 두 날짜 간의 차이를 .. 2020. 12. 15.
파이썬 OpenCV를 사용하여 Python의 이미지에 노이즈 (Gaussian / salt and pepper 등)를 추가하는 방법 OpenCV를 사용하는 Python 또는 이미지에 Gaussian 또는 salt and pepper 노이즈를 추가하는 다른 Python 이미지 처리 라이브러리가있는 일부 기능이 있는지 궁금합니다. 예를 들어, MATLAB에는 동일한 작업을 수행하는 간단한 함수가 있습니다. 또는 OpenCV와 함께 Python을 사용하여 이미지에 노이즈를 추가하는 방법은 무엇입니까? 해결 방법 이 함수는 이미지에 가우스, 소금 후추, 푸 아송 및 얼룩 노이즈를 추가합니다. Parameters ---------- image : ndarray Input image data. Will be converted to float. mode : str One of the following strings, selecting the ty.. 2020. 12. 15.
파이썬 Creating a zero-filled pandas data frame 주어진 크기의 0으로 채워진 팬더 데이터 프레임을 만드는 가장 좋은 방법은 무엇입니까? 나는 사용했다 : zero_data = np.zeros(shape=(len(data),len(feature_list))) d = pd.DataFrame(zero_data, columns=feature_list) 더 나은 방법이 있습니까? 해결 방법 이것을 시도 할 수 있습니다. d = pd.DataFrame(0, index=np.arange(len(data)), columns=feature_list) 참조 페이지 https://stackoverflow.com/questions/22963263 2020. 12. 15.
파이썬 How to read a file in reverse order? 파이썬을 사용하여 역순으로 파일을 읽는 방법? 마지막 줄에서 첫 줄까지 파일을 읽고 싶습니다. 해결 방법 for line in reversed(open("filename").readlines()): print line.rstrip() 그리고 Python 3 : for line in reversed(list(open("filename"))): print(line.rstrip()) 참조 페이지 https://stackoverflow.com/questions/2301789 2020. 12. 15.
파이썬 Parsing HTTP Response in Python 문자열을 dict로 변환하여 반복 할 수있는 방법이 있습니까? 아니면 그대로 (str 유형) 파싱해야합니까? from urllib.request import urlopen url = 'http://www.quandl.com/api/v1/datasets/FRED/GDP.json' response = urlopen(url) print(response.read()) # returns string with info 해결 방법 response.read () 를 인쇄했을 때 b 가 문자열 앞에 붙는 것을 발견했습니다 (예 : b '{ "a": 1, .. ). "b"는 바이트를 의미하며 처리중인 객체 유형에 대한 선언 역할을합니다. json.loads ( 'string') 를 사용하여 문자열을 dict로 변환 할 수.. 2020. 12. 15.
파이썬 Get date and time when photo was taken from EXIF data using PIL 해결 방법 from PIL import Image def get_date_taken(path): return Image.open(path)._getexif()[36867] 참조 페이지 https://stackoverflow.com/questions/23064549 2020. 12. 15.
파이썬 Postgres 테이블에 DataFrame을 작성하는 방법은 무엇입니까? DataFrame.to_sql 메소드가 있지만 mysql, sqlite 및 oracle 데이터베이스에서만 작동합니다. 이 메서드 postgres 연결 또는 sqlalchemy 엔진으로 전달할 수 없습니다. 해결 방법 from sqlalchemy import create_engine engine = create_engine('postgresql://scott:tiger@localhost:5432/mydatabase') df.to_sql('table_name', engine) import sql # the patched version (file is named sql.py) sql.write_frame(df, 'table_name', con, flavor='postgresql') 참조 페이지 https://.. 2020. 12. 15.
파이썬으로 BDD 연습하기 행동 기반 개발을 실행하기 위해 파이썬에 사용할 수있는 가장 진보 된 프레임 워크와 도구는 무엇입니까? 특히 루 비용 rspec 및 mocha와 유사한 도구를 찾는 것이 좋습니다. 해결 방법 참조 페이지 https://stackoverflow.com/questions/231371 2020. 12. 15.
파이썬에서 행렬 열 합계 열 0의 항목을 잘 합할 수 있습니다. 그러나 행렬의 열 2, 3 또는 4를 더하도록 코드를 어디에서 변경합니까? 나는 쉽게 당황합니다. def main(): matrix = [] for i in range(2): s = input("Enter a 4-by-4 matrix row " + str(i) + ": ") items = s.split() # Extracts items from the string list = [ eval(x) for x in items ] # Convert items to numbers matrix.append(list) print("Sum of the elements in column 0 is", sumColumn(matrix)) def sumColumn(m): for colum.. 2020. 12. 15.