python3

python3 で、csv ファイルの日付・数字を読み取る方法

投稿日:

csv をインポートすると、row in reader はリストになっている。

次のようにして、各行の要素を取り出して表示することができる。

import csv

with open('data.csv', 'r') as csv_file:
    reader = csv.reader(csv_file)
    for row in reader:
        print(row[0] + ' ' + row[2])

data.csv

"2021/01/10 02:34:10","JPY","買い","1,713.12"
"2022/03/08 12:20:32","USD","売り","9876"
"2022/12/31 18:07:55","EUR","買い","1,234,888.9"

結果

2021/01/10 02:34:10 買い
2022/03/08 12:20:32 売り
2022/12/31 18:07:55 買い

-python3
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

python3 で、リストを pop したものの返り値

リストを pop すると、 pop された値が返される。 例 plant_1 = [’pumpkin’, ‘ginger’, ‘potato’] plant_2 = [] print( …

no image

python3 でリストを結合する方法

2つのリストを結合して、「リストのリストを作りたい場合」と、「1つの長いリストを作りたい」場合がある。 それぞれ、次のようにする。 例 # リスト2つを用意 l_1 = [1,2,3] l_2 …

no image

matplotlib でエラーバーを設定する方法

pyplot.errorbar を使って設定する。 オプションの詳細は https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.erro …

no image

matplotlib で、x,y の軸上の数値を表示する方法

ax の xtics と ytics を使って表示する。 詳細は次のドキュメントを参照。 https://matplotlib.org/stable/gallery/lines_bars_and_ma …

no image

matplotlib で、凡例を表示する位置を変更する方法

凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …