There are multiple ways of installing IPython. This page contains simplified installation instructions that should work for most users. Our official documentation containsmore detailed instructionsfor manual installation targeted at advanced users and developers.
If you are looking for installation documentation for the notebook and/or qtconsole, those are now part ofJupyter.
I already have Python
If you already have Python installed and are familiar with installing packages, you can get IPython withpip:
pip install ipython
I am getting started with Python
For new users who want to install a full Python environment for scientific computing and data science, we suggest installing the Anaconda or Canopy Python distributions, which provide Python, IPython and all of its dependences as well as a complete set of open source packages for scientific computing and data science.
Download and install Continuum’sAnacondaor the free edition of Enthought’sCanopy.
Update IPython to the current version using the Terminal:
import cmath # 복소수 계산을 위해 cmath 모듈 사용
def solve_quadratic(a, b, c):
# 판별식 계산
discriminant = b**2 - 4*a*c
# 근의 공식 사용
root1 = (-b + cmath.sqrt(discriminant)) / (2 * a)
root2 = (-b - cmath.sqrt(discriminant)) / (2 * a)
return root1, root2
# 예시: a, b, c 값 입력
a = 1 # x^2의 계수
b = -3 # x의 계수
c = 2 # 상수항
# 함수 호출하여 근 구하기
roots = solve_quadratic(a, b, c)
# 결과 출력
print(f"방정식의 근: {roots[0]} 과 {roots[1]}")
from bs4 import BeautifulSoup
from markdownify import markdownify as md
import os
def convert_html_table_to_md(html_file_path, output_md_file_path):
# HTML 파일 읽기
with open(html_file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
# BeautifulSoup을 사용하여 HTML 파싱
soup = BeautifulSoup(html_content, 'html.parser')
# HTML을 Markdown으로 변환
markdown_content = md(str(soup))
# 결과를 Markdown 파일로 저장
with open(output_md_file_path, 'w', encoding='utf-8') as file:
file.write(markdown_content)
print(f"Converted HTML table to Markdown and saved as: {output_md_file_path}")
# 사용 예시
#html_file_path = 'path_to_your_html_file.html' # 변환할 HTML 파일 경로
html_file_path = 'test_001.html' # 변환할 HTML 파일 경로
output_md_file_path = 'output_markdown_file.md' # 저장할 Markdown 파일 경로
convert_html_table_to_md(html_file_path, output_md_file_path)
Ibis defines a Python dataframe API that executes on any query engine – the frontend for any backend data platform, with 20+ backends today. This allows Ibis to have excellent performance – as good as the backend it is connected to – with a consistent user experience.
What is Ibis?
Ibis is the portable Python dataframe library.
We can demonstrate this with a simple example on a few local query engines:
import ibis
ibis.options.interactive = True
DuckDB
Polars
DataFusion
PySpark
1con = ibis.connect("duckdb://")
t = con.read_parquet("penguins.parquet")
t.limit(3)
Ibis is for data engineers, data analysts, and data scientists (or any title that needs to work with data!) to use directly with their data platform(s) of choice. It also has benefits fordata platforms,organizations, andlibrary developers.
Ibis for practitioners
You can use Ibis at any stage of your data workflow, no matter your role.
Data engineerscan use Ibis to:
write and maintain complex ETL/ELT jobs
replace fragile SQL string pipelines with a robust Python API
replace PySpark with a more Pythonic API that supports Spark and many other backends
Data analystscan use Ibis to:
use Ibis interactive mode for rapid exploration
perform rapid exploratory data analysis using interactive mode
work in a general-purpose, yet easy to learn, programming language without the need for formatting SQL strings
Data scientistscan use Ibis to:
extract a sample of data for local iteration with a fast local backend
prototype with the same API that will be used in production
preprocess and feature engineer data before training a machine learning model
Ibis for data platforms
Data platforms can use Ibis to quickly bring a fully-featured Python dataframe library with minimal effort to their platform. In addition to a great Python dataframe experience for their users, they also get integrations into thebroader Python and ML ecosystem.
Often, data platforms evolve to support Python in some sequence like:
Develop a fast query engine with a SQL frontend
Gain popularity and need to support Python for data science and ML use cases
Develop a bespoke pandas or PySpark-like dataframe library and ML integrations
This third step is where Ibis comes in. Instead of spending a lot of time and money developing a bespoke Python dataframe library, you can create an Ibis backend for your data platformin as little as four hours for an experienced Ibis developeror, more typically, on the order ofoneortwomonths for a new contributor.
Why not the pandas or PySpark APIs?
Ibis for organizations
Organizations can use Ibis to standardize the interface for SQL and Python data practitioners. It also allows organizations to:
transfer data between systems
transform, analyze, and prepare data where it lives
benchmark your workload(s) across data systems using the same code
mix SQL and Python code seamlessly, with all the benefits of a general-purpose programming language, type checking, and expression validation
Ibis for library developers
Python developers creating libraries can use Ibis to:
instantly support 20+ data backends
instantly support pandas, PyArrow, and Polars objects
read and write from all common file formats (depending on the backend)
trace column-level lineage through Ibis expressions
Most Python dataframes are tightly coupled to their execution engine. And many databases only support SQL, with no Python API. Ibis solves this problem by providing a common API for data manipulation in Python, and compiling that API into the backend’s native language. This means you can learn a single API and use it across any supported backend (execution engine).
Ibis broadly supports two types of backend:
SQL-generating backends
DataFrame-generating backends
As you can see, most backends generate SQL. Ibis usesSQLGlotto transform Ibis expressions into SQL strings. You can also use the.sql()methods to mix in SQL strings, compiling them to Ibis expressions.
While portability with Ibis isn’t perfect, commonalities across backends and SQL dialects combined with years of engineering effort produce a full-featured and robust framework for data manipulation in Python.
In the long-term, we aim for a standard query plan Intermediate Representation (IR) likeSubstraitto simplify this further.
Python + SQL: better together
For most backends, Ibis works by compiling Python expressions into SQL:
g = t.group_by(["species", "island"]).agg(count=t.count()).order_by("count")
ibis.to_sql(g)
SELECT
*
FROM (
SELECT
`t0`.`species`,
`t0`.`island`,
COUNT(*) AS `count`
FROM `ibis_read_parquet_pp72u4gfkjcdpeqcawnpbt6sqq` AS `t0`
GROUP BY
1,
2
) AS `t1`
ORDER BY
`t1`.`count` ASC NULLS LAST
You can mix and match Python and SQL code:
sql = """
SELECT
species,
island,
COUNT(*) AS count
FROM penguins
GROUP BY species, island
""".strip()
DuckDB
DataFusion
PySpark
con = ibis.connect("duckdb://")
t = con.read_parquet("penguins.parquet")
g = t.alias("penguins").sql(sql)
g
This allows you to combine the flexibility of Python with the scale and performance of modern SQL.
Scaling up and out
Out of the box, Ibis offers a great local experience for working with many file formats. You can scale up with DuckDB (the default backend) or choose from other great options like Polars and DataFusion to work locally with large datasets. Once you hit scaling issues on a local machine, you can continue scaling up with a larger machine in the cloud using the same backend and same code.
If you hit scaling issues on a large single-node machine, you can switch to a distributed backend like PySpark, BigQuery, or Trino by simply changing your connection string.
Stream-batch unification
As ofIbis 8.0, the first stream processing backends have been added. Since these systems tend to support SQL, we can with minimal changes to Ibis support both batch and streaming workloads with a single API. We aim to further unify the batch and streaming paradigms going forward.
Ecosystem
Ibis is part of a larger ecosystem of Python data tools. It is designed to work well with other tools in this ecosystem, and we continue to make it easier to use Ibis with other tools over time.
Ibis already works with other Python dataframes like:
Note that theibis-frameworkpackage isnotthe same as theibispackage in PyPI. These two libraries cannot coexist in the same Python environment, as they are both imported with theibismodule name.
See thebackend support matrixfor details on operations supported.Open a feature requestif you’d like to see support for an operation in a given backend. If the backend supports it, we’ll do our best to add it quickly!
Community
Community discussions primarily take place onGitHubandZulip.
공백( ) 또는 하이픈(-)을 언더바(_)로 변경하는 프로그램을 작성할 수 있습니다. 이 프로그램은 지정된 폴더 내 모든 파일의 이름을 확인하고, 공백 또는 하이픈이 포함된 경우 이를 언더바로 대체하여 이름을 변경합니다.
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다.
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)
def replace_spaces_in_filenames(folder_path):
# 폴더 내 모든 파일을 반복
for filename in os.listdir(folder_path):
# 파일의 전체 경로 생성
old_file_path = os.path.join(folder_path, filename)
# 파일 이름에 공백이 있는지, -도 _로 변경 확인
if ' ' in filename or '-' in filename:
# 공백을 언더바로 대체
new_filename = filename.replace(' ', '_').replace('-', '_')
new_file_path = os.path.join(folder_path, new_filename)
# 파일이 존재할경우 덮어쓸지, 빠져나갈지
if os.path.exists(new_file_path):
overwrite = input(f"'{new_file_path}' already exists. Overwrite? (y/n): ")
if overwrite.lower() == 'y':
os.remove(new_file_path)
else:
print("Operation canceled.")
exit()
# 파일 이름 변경
os.rename(old_file_path, new_file_path)
print(f"Renamed: '{filename}' -> '{new_filename}'")
else:
print(f"No change: '{filename}'")
# 사용 예시
folder_path = 'path_to_your_folder' # 여기에 폴더 경로를 입력하세요
replace_spaces_in_filenames(folder_path)
프로그램 설명
os 모듈: 파일 경로와 관련된 작업을 수행하기 위해 os 모듈을 사용합니다.
폴더 내 파일 탐색:
os.listdir(folder_path)를 사용하여 지정된 폴더 내의 모든 파일 및 하위 디렉토리 이름을 가져옵니다.
for filename in os.listdir(folder_path)를 사용하여 각 파일을 순회합니다.
공백과 하이픈을 언더바로 변경:
if ' ' in filename or '-' in filename: 조건문을 사용하여 파일 이름에 공백 또는 하이픈이 포함되어 있는지 확인합니다.
filename.replace(' ', '_').replace('-', '_')를 사용하여 공백과 하이픈을 언더바로 대체합니다.
파일 이름 변경:
os.rename(old_file_path, new_file_path)를 사용하여 파일 이름을 변경합니다.
사용 방법:
folder_path에 파일 이름을 변경할 폴더의 경로를 입력합니다.
프로그램을 실행하면 폴더 내 모든 파일의 이름에서 공백과 하이픈이 언더바로 변경됩니다.
사용 예시
폴더 경로를 지정하여 프로그램을 실행하면, 그 폴더 안의 모든 파일 이름에서 공백 또는 하이픈이 언더바로 변경됩니다. 예를 들어, path_to_your_folder가 C:/Users/YourName/Documents/TestFolder인 경우:
To craft and dissect paths, ensuring compatibility across realms (operating systems):
import os
# Craft a path compatible with the underlying OS
path = os.path.join('mystic', 'forest', 'artifact.txt')
# Retrieve the tome's directory
directory = os.path.dirname(path)
# Unveil the artifact's name
artifact_name = os.path.basename(path)
2. Listing Directory Contents
To reveal all entities within a mystical directory:
import os
contents = os.listdir('enchanted_grove')
print(contents)
3. Creating Directories
To conjure new directories within the fabric of the filesystem:
import os
# create a single directory
os.mkdir('alchemy_lab')
# create a hierarchy of directories
os.makedirs('alchemy_lab/potions/elixirs')
4. Removing Files and Directories
To erase files or directories, banishing their essence:
import os
# remove a file
os.remove('unnecessary_scroll.txt')
# remove an empty directory
os.rmdir('abandoned_hut')
# remove a directory and its contents
import shutil
shutil.rmtree('cursed_cavern')
5. Executing Shell Commands
To invoke the shell’s ancient powers directly from Python:
import subprocess
# Invoke the 'echo' incantation
result = subprocess.run(['echo', 'Revealing the arcane'], capture_output=True, text=True)
print(result.stdout)
6. Working with Environment Variables
To read and inscribe upon the ethereal environment variables:
import os
# Read the 'PATH' variable
path = os.environ.get('PATH')
# Create a new environment variable
os.environ['MAGIC'] = 'Arcane'
7. Changing the Current Working Directory
To shift your presence to another directory within the filesystem:
import os
# Traverse to the 'arcane_library' directory
os.chdir('arcane_library')
8. Path Existence and Type
To discern the existence of paths and their nature — be they file or directory:
import os
# Check if a path exists
exists = os.path.exists('mysterious_ruins')
# Ascertain if the path is a directory
is_directory = os.path.isdir('mysterious_ruins')
# Determine if the path is a file
is_file = os.path.isfile('ancient_manuscript.txt')
9. Working with Temporary Files
To summon temporary files and directories, fleeting and ephemeral:
import tempfile
# Create a temporary file
temp_file = tempfile.NamedTemporaryFile(delete=False)
print(temp_file.name)
# Erect a temporary directory
temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)
10. Getting System Information
To unveil information about the host system, its name, and the enchantments it supports:
import os
import platform
# Discover the operating system
os_name = os.name # 'posix', 'nt', 'java'
# Unearth detailed system information
system_info = platform.system() # 'Linux', 'Windows', 'Darwin'