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

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

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

no image

matplotlib で、縦横の罫線を引く方法

破線をカスタマイズする方法 以下では、dashes = [5,2,2,2] で、線5・空白2・線2・空白2の破線を指定している。 詳しくは次を参照。 https://matplotlib.org/st …

no image

matplotlib で、縦横の線(グリッド)を描く方法

pyplot grid で縦横線(罫線のようなもの)を引くことができる。 例 from matplotlib import pyplot as plt data_x = [25,26,27] …

no image

matplotlib で、軸に垂直・平行な線を書く方法

axhline, axvline を使ってx,y軸に平行な線を描くことができる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot …

no image

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

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