0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Python / SQL]CSVファイルを読み込んだあと、SQLで確認する

Last updated at Posted at 2022-03-31

やりたいこと

  • CSVファイルをデータフレームで読み込んだ後、SQLで出力する

サンプルデータ

image.png

Step 1

  • CSVファイルを読み込む
%pyspark
import pandas as pd
# Hadoppにあるファイルを読み込む
df_csv = pd.read_csv('test.csv', sep=',' )
# python から sparkにに変換したものをテーブルにいれる
# create みたいなの使ってた
print(df_csv)

# pandas dataframe を spark dataframeに変換
df=spark.createDataFrame(df_csv)

# sqlで使えるように一時テーブルとして登録
df.createOrReplaceTempView('test_1')


Step 2

  • SQLで確認
select *
from test_1
limit 10
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?