0

I type some code to show the relationship between price and datetime about bitcoin.So I want to draw the graph to show them BUT it fail, i dont know the reason, please give me some tips,thanks a lot.

below is my code

import numpy as np
import matplotlib.pyplot as plt


import pandas as pd
df = pd.read_csv(r'D:\downloads\BTC-USD.csv', date_parser = True)


df.columns = ['datetime','open','high','low','close','adj', 'vol']

print(df.head(5))

df.index = df['datetime']




df.datetime=pd.to_numeric(df.datetime,errors='coerce')
df.adj=pd.to_numeric(df.adj,errors='coerce')

print(df[['datetime', 'adj']].plot(kind = 'line', figsize=[20,5]))

below is the terminal result

PS D:\python> python test3.py
0  2020-10-30  13437.874023  ...  13546.522461  30581485201
1  2020-10-31  13546.532227  ...  13780.995117  30306464719
2  2020-11-01  13780.995117  ...  13737.109375  24453857900
3  2020-11-02  13737.032227  ...  13550.489258  30771455468
4  2020-11-03  13550.451172  ...  13950.300781  29869951617

[5 rows x 7 columns]
PS D:\python> python test3.py
     datetime          open  ...           adj          vol
0  2020-10-30  13437.874023  ...  13546.522461  30581485201
1  2020-10-31  13546.532227  ...  13780.995117  30306464719
2  2020-11-01  13780.995117  ...  13737.109375  24453857900
3  2020-11-02  13737.032227  ...  13550.489258  30771455468
4  2020-11-03  13550.451172  ...  13950.300781  29869951617

[5 rows x 7 columns]
AxesSubplot(0.125,0.11;0.775x0.77)
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • Did you update conda? If so, does this answer your question? [After conda update, python kernel crashes when matplotlib is used](https://stackoverflow.com/q/69786885/7758804) – Trenton McKinney Nov 01 '21 at 11:48
  • 1
    Also if you're plotting from a file, it needs `plt.show()` after `df[['datetime', 'adj']].plot(kind = 'line', figsize=[20,5])`. – Trenton McKinney Nov 01 '21 at 11:52
  • Thankyou very much, After I installed anaconda, I successly plot the graph. (I failed whiling using pip) – 良心燈塔 Nov 03 '21 at 08:22

1 Answers1

0

There's no need to use the print function. Just call

df[['datetime', 'adj']].plot(kind = 'line', figsize=[20,5])