0
1

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.

csvファイルとpandasのDataFrameの変換

Posted at

はじめに

データ分析において、Excelで物足りないときはpandasを使うと便利なことが多々あります。
今回はcsvファイルを想定しての記載です。

環境

  • python3:3.9.12
  • numpy:1.21.5
  • pandas:1.4.2

pandasのDataFrameからcsvファイルへの保存

write_csv.py
import numpy as np
import pandas as pd

dates = pd.date_range("20220612", periods=6)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))

df.to_csv('sample.csv')

csvファイルからpandasのDataFrameへの読み込み

read_csv.py
import pandas as pd

df = pd.read_csv('sample.csv', index_col=0)
print(df)

おわりに

ご覧いただき、ありがとうございました。
こちら初めての投稿になります。励みになりますので、お気軽にご意見・ご感想いただけると幸いです。
よろしくお願いします。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?