Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
35
Help us understand the problem. What is going on with this article?
@nanoshodo

Python3でCSVファイルを読み込んでグラフに表示させる

More than 3 years have passed since last update.

CSVファイル読み込んで、グラフとして表示させてみます。

ファイルを読み込むには pandasモジュールを使ってみます。

import pandas as pd

read_csvでCSVファイルを読み込みます。(カンマ(,)で区切られてるCSVファイルの場合)

df = pd.read_csv('test1.csv') 

ちなみにtest1.csvの中身は下記の通りです。

test1.csv
1,333
2,572
3,126
4,783
5,890
6,333
7,572
8,126
9,783
10,890

グラフに変換するモジュールは matplotlib を使います。

import matplotlib.pyplot as plt

全体のコード

main.py
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('test.csv', names=['num1', 'num2'])
plt.plot(range(0,10),df['num2'],marker="o")
plt.show()

download.png

参考:
PythonでCSVファイルをもとに折れ線グラフを描く例
https://snap.textfile.org/20161101235123/

35
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
35
Help us understand the problem. What is going on with this article?