반응형
1. Pandas

Pandas is a software library written for the python programming language for data manipulation and analysis.

Pandas is well suited for many different kinds of data:
  • Tabular data with heterogeneously-types columns.
  • Ordered and unordered time series data.
  • Arbitrary matrix data with row and column labels.
  • Any other form of observational / statistical data sets.
 The data actually need not be labeled at all to be placed into a pandas data structure.

2. NumPy

Numpy is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays.



3. Matplotlib

Matplotlib is a Python package used for 2D graphics.
  • Bar graph
  • Histograms
  • Scatter Plot
  • Pie Plot
  • Hexagonal Bin Plot
  • Area Plot

 


4. Selenium

The selenium package is used to automate web browser interaction from Python.


5. OpenCV

OpenCV- Python is a library of Python designed to solve computer vision problems.


6. SciPy

Scipy is a free and open-source Python library used for scientific computing and technical computing.


7. Scikit-Learn

Scikit-learn (formerly scikits.learn) is a free software machine learning library for the Python programming language. It features various classification, regression and clustering algorithms.


8.  PySpark

The Spark Python API (PySpark) exposes the Spark programming model to Python.



9. Django

Diango is a Python web framework. A framework provides a structure and common methods to make the life of a web application developer much easier for building flexible, scalable and maintainable web applications

  • Django is a high-level and has a MVC-MVT styled architecture.
  • Django web framework is written on quick and powerful Python language.
  • Django has a open-source collection of libraries for building a fully functioning web application.


10. Tensor Flow

TensorFlow is a Python library used to implement deep networks. In TensorFlow, computation is approached as a dataflow graph.


반응형
반응형

[python] pdf to png, 해상도 높게 저장하기 

 

import fitz  # PyMuPDF

def pdf_to_png(pdf_file, output_folder, dpi=300):
    # Open the PDF file
    pdf_document = fitz.open(pdf_file)
    
    for page_number in range(pdf_document.page_count):
        # Get the page
        page = pdf_document[page_number]
        
        # Set the resolution (DPI)
        zoom = dpi / 72.0
        mat = fitz.Matrix(zoom, zoom)
        image = page.get_pixmap(matrix=mat)
        
        # Save the image as a PNG file
        image.save(f"{output_folder}/page_{page_number + 1}.png", "png")

    # Close the PDF file
    pdf_document.close()

if __name__ == "__main__":
    input_pdf = "input.pdf"  # Replace with your PDF file path
    output_folder = "output_images"  # Replace with your output folder
    dpi = 600  # Adjust DPI as needed
    
    pdf_to_png(input_pdf, output_folder, dpi)
반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] PyAudio  (0) 2023.10.20
[Python] savefig 0.0.4  (0) 2023.10.17
[python] matrix 3.0.0  (0) 2023.10.04
[python] 알고리즘 - 탐색  (0) 2023.09.27
[python] 알고리즘 - 정렬  (0) 2023.09.27
반응형

[python] sudoku 만들기 - 랜덤 문제 

#sudoku puzzle create using python chatGPT
import random

def generate_solved_sudoku():
    base  = 3
    side  = base*base
    # pattern for a baseline valid solution
    def pattern(r,c): return (base*(r%base)+r//base+c)%side

    # randomize rows, columns and numbers (of valid base pattern)
    def shuffle(s): return random.sample(s,len(s)) 
    rBase = range(base) 
    rows  = [ g*base + r for g in shuffle(rBase) for r in shuffle(rBase) ] 
    cols  = [ g*base + c for g in shuffle(rBase) for c in shuffle(rBase) ]
    nums  = shuffle(range(1,base*base+1))

    # produce board using randomized baseline pattern
    board = [ [nums[pattern(r,c)] for c in cols] for r in rows ]
    
    return board

def print_sudoku(board):
    for i in range(9):
        if i % 3 == 0 and i != 0:
            print("- - - - - - - - - - - -")
        for j in range(9):
            if j % 3 == 0 and j != 0:
                print("|", end=" ")
            print(board[i][j], end=" ")
        print()

def remove_numbers(board, difficulty_level):
    """
    Remove numbers from the solved Sudoku grid based on the difficulty level.
    """
    if difficulty_level == 'easy':
        num_to_remove = 30  # Easy: 30 numbers removed
    elif difficulty_level == 'medium':
        num_to_remove = 40  # Medium: 40 numbers removed
    else:
        num_to_remove = 50  # Hard: 50 numbers removed
    
    for _ in range(num_to_remove):
        row = random.randint(0, 8)
        col = random.randint(0, 8)
        if board[row][col] != 0:
            board[row][col] = 0

# Generate a solved Sudoku puzzle
solved_sudoku = generate_solved_sudoku()

# Print the solved Sudoku puzzle
print("Solved Sudoku Puzzle:")
print_sudoku(solved_sudoku)

# Create a copy of the solved puzzle
unsolved_sudoku = [row[:] for row in solved_sudoku]

# Remove numbers to create a puzzle
difficulty_level = 'medium'  # Change difficulty level as needed ('easy', 'medium', 'hard')
remove_numbers(unsolved_sudoku, difficulty_level)

# Print the unsolved Sudoku puzzle (the generated puzzle)
print("\nUnsolved Sudoku Puzzle:")
print_sudoku(unsolved_sudoku)
반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] 알고리즘 - 탐색  (0) 2023.09.27
[python] 알고리즘 - 정렬  (0) 2023.09.27
[python] sudoku 만들기  (0) 2023.09.27
[python] How to send text messages with Python for Free  (0) 2023.09.26
[python] algorithm, 알고리즘  (0) 2023.09.20
반응형

# sudoku using python

def is_valid_move(board, row, col, num):
    """
    Check if placing 'num' at position (row, col) is a valid move.
    """
    # Check the row
    if num in board[row]:
        return False

    # Check the column
    if num in [board[i][col] for i in range(9)]:
        return False

    # Check the 3x3 subgrid
    start_row, start_col = 3 * (row // 3), 3 * (col // 3)
    for i in range(start_row, start_row + 3):
        for j in range(start_col, start_col + 3):
            if board[i][j] == num:
                return False

    return True

def solve_sudoku(board):
    """
    Solve the Sudoku puzzle using backtracking.
    """
    empty_cell = find_empty_cell(board)

    if not empty_cell:
        # Puzzle is solved
        return True

    row, col = empty_cell

    for num in range(1, 10):
        if is_valid_move(board, row, col, num):
            board[row][col] = num

            if solve_sudoku(board):
                return True

            # If the current placement doesn't lead to a solution, backtrack
            board[row][col] = 0

    # No valid move found, need to backtrack
    return False

def find_empty_cell(board):
    """
    Find an empty cell in the Sudoku grid.
    """
    for i in range(9):
        for j in range(9):
            if board[i][j] == 0:
                return (i, j)
    return None

def print_board(board):
    """
    Print the Sudoku grid.
    """
    for i in range(9):
        if i % 3 == 0 and i != 0:
            print("- - - - - - - - - - - -")
        for j in range(9):
            if j % 3 == 0 and j != 0:
                print("|", end=" ")
            print(board[i][j], end=" ")
        print()

# Example Sudoku puzzle (0 represents empty cells)
sudoku_board = [
    [5, 3, 0, 0, 7, 0, 0, 0, 0],
    [6, 0, 0, 1, 9, 5, 0, 0, 0],
    [0, 9, 8, 0, 0, 0, 0, 6, 0],
    [8, 0, 0, 0, 6, 0, 0, 0, 3],
    [4, 0, 0, 8, 0, 3, 0, 0, 1],
    [7, 0, 0, 0, 2, 0, 0, 0, 6],
    [0, 6, 0, 0, 0, 0, 2, 8, 0],
    [0, 0, 0, 4, 1, 9, 0, 0, 5],
    [0, 0, 0, 0, 8, 0, 0, 7, 9]
]

print("Sudoku Puzzle:")
print_board(sudoku_board)
print("\nSolving...\n")

if solve_sudoku(sudoku_board):
    print("Sudoku Solution:")
    print_board(sudoku_board)
else:
    print("No solution exists.")
반응형
반응형

[한빛미디어] "이것이 취업을 위한 코딩 테스트다 with 파이썬" 전체 소스코드 저장소입니다
https://github.com/ndb796/python-for-coding-test

Types of Algorithm

    Searching
    Sorting
    Recursive
    Backtracking
    Greedy
    Randomized
    Divide & Conquer
    Dynamic Programing


 https://www.instagram.com/p/CxZgarwyv_2/?igshid=MjNiZGVkZTJkZQ%3D%3D 



https://www.geeksforgeeks.org/python-data-structures-and-algorithms/

반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] sudoku 만들기  (0) 2023.09.27
[python] How to send text messages with Python for Free  (0) 2023.09.26
[python] GUI 비밀번호 자동 생성기  (0) 2023.09.18
[python] pyperclip  (0) 2023.09.18
[Python] kivy  (0) 2023.09.15
반응형

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.

https://pypi.org/project/PyMuPDF/

>> pip install PyMuPDF

 

https://mupdf.com/

 

1.디렉토리 안의 pdf 파일을 읽어들여서 리스트 목록을 출력

2.파일명을 넘기면 파일명_이미지순서.png 파일을 생성. 

import fitz  # PyMuPDF

 
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다. 
import os
from pathlib import Path
# src 상위 폴더를 실행폴더로 지정하려고 한다.
###real_path = Path(__file__).parent.parent
real_path = Path(__file__).parent
print(real_path)
#작업 디렉토리 변경
os.chdir(real_path) 

directory_base = str(real_path)+"./ONE/"  # 경로object를 문자열로 변경해서 합친다. 
 


def pdf_to_png(pdf_file, input_pdf_name, output_folder):
    # Open the PDF file
    pdf_document = fitz.open(pdf_file)
    
    for page_number in range(pdf_document.page_count):
        # Get the page
        page = pdf_document[page_number]
        
        # Convert the page to an image
        image = page.get_pixmap()
        
        # Save the image as a PNG file
        image.save(f"{output_folder}/{input_pdf_name}_{page_number + 1}.png", "png")

    # Close the PDF file
    pdf_document.close()

if __name__ == "__main__":
     
    # List all files in the directory
    file_list = [f for f in os.listdir(directory_base) if os.path.isfile(os.path.join(directory_base, f))]

    # Print the list of files
    for file in file_list:
        print(file)
        
        #input_pdf = "./TWO/"+ file_name +".pdf"  # Replace with your PDF file path
        input_pdf      = "./ONE/"+ file  # Replace with your PDF file path
        input_pdf_name = os.path.splitext(file)[0]
        print(input_pdf_name)
        output_folder  = "./ONE/data"  # Replace with your output folder
        
        pdf_to_png(input_pdf, input_pdf_name, output_folder)

 

반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] pyperclip  (0) 2023.09.18
[Python] kivy  (0) 2023.09.15
[python] PyMuPDF로 코딩 없이 PDF에서 이미지 추출  (0) 2023.09.14
[python] cowsay  (0) 2023.09.14
[PYTHON] Python tkinter 강좌  (0) 2023.08.25
반응형

[python] chatGPT에게 TicTacToe 만들어달라고 했다. 

import tkinter as tk
from tkinter import messagebox

class TicTacToe:
    def __init__(self, root):
        self.root = root
        self.root.title("Tic-Tac-Toe")

        self.current_player = "X"
        self.board = [""] * 9

        self.buttons = []
        for i in range(9):
            button = tk.Button(root, text="", width=10, height=3, command=lambda i=i: self.make_move(i))
            button.grid(row=i // 3, column=i % 3)
            self.buttons.append(button)

    def make_move(self, position):
        if not self.board[position]:
            self.board[position] = self.current_player
            self.buttons[position].config(text=self.current_player)
            
            if self.check_winner():
                messagebox.showinfo("Game Over", f"Player {self.current_player} wins!")
                self.reset_game()
            elif all(cell != "" for cell in self.board):
                messagebox.showinfo("Game Over", "It's a draw!")
                self.reset_game()
            else:
                self.current_player = "O" if self.current_player == "X" else "X"

    def check_winner(self):
        winning_combinations = [(0, 1, 2), (3, 4, 5), (6, 7, 8),
                                (0, 3, 6), (1, 4, 7), (2, 5, 8),
                                (0, 4, 8), (2, 4, 6)]

        for combo in winning_combinations:
            if self.board[combo[0]] == self.board[combo[1]] == self.board[combo[2]] != "":
                return True
        return False

    def reset_game(self):
        self.current_player = "X"
        self.board = [""] * 9
        for button in self.buttons:
            button.config(text="")

if __name__ == "__main__":
    root = tk.Tk()
    game = TicTacToe(root)
    root.mainloop()
반응형
반응형

https://pypi.org/project/secure-smtplib/

 

secure-smtplib

Secure SMTP subclasses for Python 2

pypi.org

secure-smtplib 0.1.1

 

pip install secure-smtplib

 

 

.chatGPT에게 " python email sending app " 이라고 질문했다. 

# chatGPT - python email sending app 
import tkinter as tk
from tkinter import messagebox
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_email():
    sender_email = sender_email_entry.get()
    sender_password = sender_password_entry.get()
    recipient_email = recipient_email_entry.get()
    subject = subject_entry.get()
    message = message_text.get("1.0", tk.END)
    
    try:
        # Set up the SMTP server
        smtp_server = smtplib.SMTP("smtp.gmail.com", 587)
        smtp_server.starttls()
        smtp_server.login(sender_email, sender_password)
        
        # Create the email
        email = MIMEMultipart()
        email["From"] = sender_email
        email["To"] = recipient_email
        email["Subject"] = subject
        email.attach(MIMEText(message, "plain"))
        
        # Send the email
        smtp_server.sendmail(sender_email, recipient_email, email.as_string())
        smtp_server.quit()
        
        messagebox.showinfo("Success", "Email sent successfully!")
    except Exception as e:
        messagebox.showerror("Error", f"An error occurred: {str(e)}")

# Create the main GUI window
root = tk.Tk()
root.title("Email Sending App")

# Create and place widgets
sender_email_label = tk.Label(root, text="Sender Email:")
sender_email_label.pack()

sender_email_entry = tk.Entry(root)
sender_email_entry.pack()

sender_password_label = tk.Label(root, text="Sender Password:")
sender_password_label.pack()

sender_password_entry = tk.Entry(root, show="*")
sender_password_entry.pack()

recipient_email_label = tk.Label(root, text="Recipient Email:")
recipient_email_label.pack()

recipient_email_entry = tk.Entry(root)
recipient_email_entry.pack()

subject_label = tk.Label(root, text="Subject:")
subject_label.pack()

subject_entry = tk.Entry(root)
subject_entry.pack()

message_label = tk.Label(root, text="Message:")
message_label.pack()

message_text = tk.Text(root, height=10, width=40)
message_text.pack()

send_button = tk.Button(root, text="Send Email", command=send_email)
send_button.pack()

root.mainloop()
반응형

+ Recent posts