I want to create a chart for bitcoin price
To create my chart i use this script:
while True:
url = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd").json()
price = url['bitcoin']['usd']
f = open("chart.csv", "a")
now = time.time()
f.write(str(price) + ", " + str(now) + "\n")
f.close()
time.sleep(120)
which gives me following output:
47742, 1614355728.759062
47742, 1614355849.1553347
47935, 1614355969.668541
47935, 1614356090.0655239
47922, 1614356210.4580832
47922, 1614356331.5841808
47900, 1614356453.6750243
47900, 1614356574.6440663
And when i try to plot the data with matplotlib i use this script:
plt.plot(price, date)
plt.title('Bitcoin Price Chart')
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()
for my variables price and date i want to use the columns from my csv file, but since i dont have any header how can i do this?
I tried to turn the csv file into a numpy array like this
file = open("chart.csv")
numpy_array = np. loadtxt(file, delimiter=",")
print(numpy_array)
Which prints out a nice array, however if i want to split up the array i still cant do it.
I tried print(numpy_array[0])
but this prints out only the first row.
How can i get the first column and second column so i can than use those for my price and date variables?
pandas.read_csv?