๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ


Python/Basic

(27)
[Python] curve fitting ๋ฐ‘์ด ์ž์—ฐ์ƒ์ˆ˜ e์ธ ์ง€์ˆ˜ํ•จ์ˆ˜ x = np.arange(-2, 4, 0.1) y = np.exp(x) plt.plot(x, y, label='e^x') plt.legend() plt.show() ์ž์—ฐ๋กœ๊ทธ ํ•จ์ˆ˜ x = np.arange(0.1, 4, 0.1) y = np.log(x) plt.plot(x, y, label='y = log x') plt.legend() plt.show() ์ง€์ˆ˜ ํ•จ์ˆ˜ curve fitting from scipy.optimize import curve_fit import matplotlib.pyplot as plt # a*e^(-b*x)+c def func1(x, a, b, c): return a * np.exp(-b * x) + c def func2(x, a, b, c): ret..
[Python] Pillow ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ ํ™•์ธ https://note.nkmk.me/en/python-opencv-pillow-image-size/ Get image size (width, height) with Python, OpenCV, Pillow (PIL) | note.nkmk.me This article describes how to get the image size (width, height) in Python with OpenCV and Pillow (PIL).The image size can be obtained as a tuple with the attribute shape of ndarray in OpenCV and the attribute size of PIL.Image in Pillow (PIL). Note that t note..
[Python] PDF ๊ด€๋ จ ํŒจํ‚ค์ง€ ์ •๋ฆฌ PDFRW https://github.com/pmaupin/pdfrw GitHub - pmaupin/pdfrw: pdfrw is a pure Python library that reads and writes PDFs pdfrw is a pure Python library that reads and writes PDFs - GitHub - pmaupin/pdfrw: pdfrw is a pure Python library that reads and writes PDFs github.com https://kimhwon.github.io/pdfrw-automation/ pdfrw๋ฅผ ์‚ฌ์šฉํ•œ PDF ์—…๋ฌด ์ž๋™ํ™” PDF ํผ์„ ์ฑ„์šฐ๋Š” ์—…๋ฌด๋ฅผ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค. ๋Œ€๋žต 600 rows ์ฏค ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„๋ฅ˜ํ•ด์„œ PDF์— ์ฑ„์›Œ ๋„ฃ..
[Python] ํŒŒ์ผ ๊ด€๋ จ ํ•ด๋‹น ๊ฒฝ๋กœ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ list ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜ os.listdir(path) Data๋ฅผ ํฌํ•จํ•˜๋Š” ํŒŒ์ผ๋ช… ์ฐพ๊ธฐ file_name = [s for s in files if "Data" in s] with os.scandir(path) as files: for file in files: print(file.name) ํŒŒ์ผ ๋ณต์‚ฌ ํ•˜๊ธฐ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๋Š” copyfile, copy, copy2 ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์€ ๊ฐ™์Šต๋‹ˆ๋‹ค. import shutil shutil.copyfile("./test1/test1.txt", "./test2.txt") shutil.copy("./test1/test1.txt", "./test3.txt") shutil.copy2("./test1/test1.txt", "./test4.txt") ..
[Python] Excel, Word ๋‹ค๋ฃจ๊ธฐ Excel openpyxl from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.styles import PatternFill class Copy_excel: def __init__(self, src): self.wb = load_workbook(src) def select_sheet(self, sheet_nm): self.ws = self.wb[sheet_nm] # Write the value in the cell defined by row_dest+column_dest def write_workbook(self, row_dest, column_dest, value): c = self.ws.cell(row = row..
[Python] XlsxWriter - Excel ๋‹ค๋ฃจ๊ธฐ Pandas - Dataframe๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ writer = pd.ExcelWriter(out_file, engine='xlsxwriter') df.to_excel(writer, sheet_name='Sheet1', freeze_panes = (1, 0), index=False) workbook = writer.book worksheet = writer.sheets['Sheet1'] worksheet.set_zoom(80) # zoom ์„ค์ • # row, col, width, format worksheet.set_column(0, 0, 10, workbook.add_format({'num_format': '#,##0', 'border': 1, 'align': 'center', 'text_wrap': ..
[Python] sqlalchemy, json์œผ๋กœ ๋ณ€๊ฒฝ ํ›„ ๋ฆฌํ„ด user = User.query df = pd.read_sql(user.statement, user.session.bind) #df = df.drop(columns=['updated_datetime']) df.columns = map(str.lower, df.columns) result_json = json.loads(df.astype(str).to_json(orient='records', double_precision=15, date_format='iso')) result_json = json.dumps(result_json).replace('None', '') result_json = json.loads(result_json)
[Python] Pandas - Dataframe : apply, lambda ์ด์šฉํ•œ ๊ฐ’ ๋ณ€๊ฒฝ df = pd.DataFrame({'test': [ '1,000' ,'20000' ,'3000' ,'4,330' ]}) df['test'] = df.apply(lambda x: x['test'].replace(",", "").replace(" ", "") if x['test'] else '', axis=1) for๋ฌธ์—์„œ ๋ณ€๊ฒฝํ•˜๊ธฐ for i, row in df.iterrows(): row.loc[i, 'age2'] = row['age'] + 10