|
| 1 | +--- |
| 2 | +jupyter: |
| 3 | + jupytext: |
| 4 | + notebook_metadata_filter: all |
| 5 | + text_representation: |
| 6 | + extension: .md |
| 7 | + format_name: markdown |
| 8 | + format_version: '1.1' |
| 9 | + jupytext_version: 1.2.0 |
| 10 | + kernelspec: |
| 11 | + display_name: Python 3 |
| 12 | + language: python |
| 13 | + name: python3 |
| 14 | + language_info: |
| 15 | + codemirror_mode: |
| 16 | + name: ipython |
| 17 | + version: 3 |
| 18 | + file_extension: .py |
| 19 | + mimetype: text/x-python |
| 20 | + name: python |
| 21 | + nbconvert_exporter: python |
| 22 | + pygments_lexer: ipython3 |
| 23 | + version: 3.6.8 |
| 24 | + plotly: |
| 25 | + description: How to create charts from csv files with Plotly and Python |
| 26 | + display_as: databases |
| 27 | + has_thumbnail: false |
| 28 | + ipynb: ~notebook_demo/84 |
| 29 | + language: python |
| 30 | + layout: user-guide |
| 31 | + name: Plot CSV Data |
| 32 | + order: 1 |
| 33 | + page_type: example_index |
| 34 | + permalink: python/plot-data-from-csv/ |
| 35 | + thumbnail: thumbnail/csv.jpg |
| 36 | + title: Plot Data from CSV | plotly |
| 37 | +--- |
| 38 | + |
| 39 | + |
| 40 | +CSV or comma-delimited-values is a very popular format for storing structured data. In this tutorial, we will see how to plot beautiful graphs using csv data, and Pandas. We will learn how to import csv data from an external source (a url), and plot it using Plotly and pandas. |
| 41 | + |
| 42 | +First we import the data and look at it. |
| 43 | + |
| 44 | +```python |
| 45 | +import pandas as pd |
| 46 | +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv') |
| 47 | +df.head() |
| 48 | +``` |
| 49 | + |
| 50 | +### Plot from CSV with Plotly Express |
| 51 | + |
| 52 | +```python |
| 53 | +import pandas as pd |
| 54 | +import plotly.express as px |
| 55 | + |
| 56 | +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv') |
| 57 | + |
| 58 | +fig = px.line(df, x = 'AAPL_x', y = 'AAPL_y', title='Apple Share Prices over time (2014)') |
| 59 | +fig.show() |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | +### Plot from CSV with `graph_objects` |
| 64 | + |
| 65 | +```python |
| 66 | +import pandas as pd |
| 67 | +import plotly.graph_objects as go |
| 68 | + |
| 69 | +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv') |
| 70 | + |
| 71 | +fig = go.Figure(go.Scatter(x = df['AAPL_x'], y = df['AAPL_y'], |
| 72 | + name='Share Prices (in USD)')) |
| 73 | + |
| 74 | +fig.update_layout(title='Apple Share Prices over time (2014)', |
| 75 | + plot_bgcolor='rgb(230, 230,230)', |
| 76 | + showlegend=True) |
| 77 | + |
| 78 | +fig.show() |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +#### Reference |
| 83 | +See https://plot.ly/python/getting-started for more information about Plotly's Python API! |
0 commit comments