<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ko">
	<id>https://devcafe.co.kr/w/index.php?action=history&amp;feed=atom&amp;title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC</id>
	<title>PANDAS 와 SQL 쿼리 - 편집 역사</title>
	<link rel="self" type="application/atom+xml" href="https://devcafe.co.kr/w/index.php?action=history&amp;feed=atom&amp;title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC"/>
	<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC&amp;action=history"/>
	<updated>2026-05-17T08:52:23Z</updated>
	<subtitle>이 문서의 편집 역사</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://devcafe.co.kr/w/index.php?title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC&amp;diff=1859&amp;oldid=prev</id>
		<title>2025년 6월 24일 (화) 03:28에 Devcafe님의 편집</title>
		<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC&amp;diff=1859&amp;oldid=prev"/>
		<updated>2025-06-24T03:28:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ko&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 이전 판&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2025년 6월 24일 (화) 12:28 판&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l52&quot;&gt;52번째 줄:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;52번째 줄:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;connection.close()&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;connection.close()&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[category:python]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[category:pandas]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Devcafe</name></author>
	</entry>
	<entry>
		<id>https://devcafe.co.kr/w/index.php?title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC&amp;diff=357&amp;oldid=prev</id>
		<title>Devcafe: 새 문서: === pandas 이용하여 sql 쿼리 조회 === &lt;source lang=sql&gt; import cx_Oracle import pandas as pd import json  # Function to load the configuration file def load_db_config(file_path):     with open(file_path, &#039;r&#039;) as f:         config = json.load(f)     return config  # Load the database configuration from the JSON file db_config = load_db_config(&#039;db_config.json&#039;) dsn_tns = cx_Oracle.makedsn(db_config[&#039;host&#039;], db_config[&#039;port&#039;], service_name=db_config[&#039;service_name&#039;]) connect...</title>
		<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=PANDAS_%EC%99%80_SQL_%EC%BF%BC%EB%A6%AC&amp;diff=357&amp;oldid=prev"/>
		<updated>2024-10-14T16:49:17Z</updated>

		<summary type="html">&lt;p&gt;새 문서: === pandas 이용하여 sql 쿼리 조회 === &amp;lt;source lang=sql&amp;gt; import cx_Oracle import pandas as pd import json  # Function to load the configuration file def load_db_config(file_path):     with open(file_path, &amp;#039;r&amp;#039;) as f:         config = json.load(f)     return config  # Load the database configuration from the JSON file db_config = load_db_config(&amp;#039;db_config.json&amp;#039;) dsn_tns = cx_Oracle.makedsn(db_config[&amp;#039;host&amp;#039;], db_config[&amp;#039;port&amp;#039;], service_name=db_config[&amp;#039;service_name&amp;#039;]) connect...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;새 문서&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== pandas 이용하여 sql 쿼리 조회 ===&lt;br /&gt;
&amp;lt;source lang=sql&amp;gt;&lt;br /&gt;
import cx_Oracle&lt;br /&gt;
import pandas as pd&lt;br /&gt;
import json&lt;br /&gt;
&lt;br /&gt;
# Function to load the configuration file&lt;br /&gt;
def load_db_config(file_path):&lt;br /&gt;
    with open(file_path, &amp;#039;r&amp;#039;) as f:&lt;br /&gt;
        config = json.load(f)&lt;br /&gt;
    return config&lt;br /&gt;
&lt;br /&gt;
# Load the database configuration from the JSON file&lt;br /&gt;
db_config = load_db_config(&amp;#039;db_config.json&amp;#039;)&lt;br /&gt;
dsn_tns = cx_Oracle.makedsn(db_config[&amp;#039;host&amp;#039;], db_config[&amp;#039;port&amp;#039;], service_name=db_config[&amp;#039;service_name&amp;#039;])&lt;br /&gt;
connection = cx_Oracle.connect(user=db_config[&amp;#039;user&amp;#039;], password=db_config[&amp;#039;password&amp;#039;], dsn=dsn_tns)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Function to execute a SQL query and return the results as a DataFrame&lt;br /&gt;
def query_to_dataframe(query, connection):&lt;br /&gt;
    return pd.read_sql_query(query, connection)&lt;br /&gt;
&lt;br /&gt;
# 1. Fetch initial data and save it as a DataFrame&lt;br /&gt;
initial_query = &amp;quot;SELECT OWNER || &amp;#039;.&amp;#039; || TABLE_NAME AS full_name FROM ALL_TABLES WHERE OWNER = &amp;#039;DBCAFE&amp;#039;&amp;quot;&lt;br /&gt;
initial_df = query_to_dataframe(initial_query, connection)&lt;br /&gt;
&lt;br /&gt;
# Display the initial DataFrame&lt;br /&gt;
print(&amp;quot;Initial DataFrame:&amp;quot;)&lt;br /&gt;
print(initial_df)&lt;br /&gt;
&lt;br /&gt;
# 2. Extract information from the DataFrame for the new SQL query&lt;br /&gt;
# Assuming we want to use the full_name column from the initial DataFrame in the new query&lt;br /&gt;
full_names = initial_df[&amp;#039;FULL_NAME&amp;#039;].tolist()&lt;br /&gt;
# Format each name with single quotes and join with commas&lt;br /&gt;
formatted_names = &amp;quot;, &amp;quot;.join(f&amp;quot;&amp;#039;{name}&amp;#039;&amp;quot; for name in full_names)&lt;br /&gt;
&lt;br /&gt;
# 3. Construct and execute a new query using the extracted information&lt;br /&gt;
new_query = f&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    SELECT * &lt;br /&gt;
    FROM ALL_TABLES &lt;br /&gt;
    WHERE (OWNER || &amp;#039;.&amp;#039; || TABLE_NAME) IN ({formatted_names})&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Fetch new data based on the extracted information&lt;br /&gt;
new_df = query_to_dataframe(new_query, connection)&lt;br /&gt;
&lt;br /&gt;
# Display the new DataFrame&lt;br /&gt;
print(&amp;quot;\nNew DataFrame:&amp;quot;)&lt;br /&gt;
print(new_df)&lt;br /&gt;
&lt;br /&gt;
# Close the connection&lt;br /&gt;
connection.close()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Devcafe</name></author>
	</entry>
</feed>