Python Forum
Issues with csv double quotes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issues with csv double quotes
#1
Hi guys, I made a Bs4 code for export a csv file with numbers but can't get rid of double quotes...
It doesn't let me manipulate the data later when I try to make any calculation...


Bit Coin Data Exported:
import requests
import bs4
import pandas as pd
import csv

from bs4 import BeautifulSoup as bs


dateList = []
openList = []
highList = []
lowList  = []
closeList= []
volumeList= []
MCapList = []

r = requests.get('https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20200315')

soup = bs(r.text,'lxml')

soup.find('tr', {'class': 'cmc-table-row'}).find('td', {'class' : 'cmc-table__cell cmc-table__cell--sticky cmc-table__cell--left'}).text

tr = soup.findAll('tr', {'class': 'cmc-table-row'})

for item in tr:
    dateList.append(item.find('td', {'class' : 'cmc-table__cell cmc-table__cell--sticky cmc-table__cell--left'}).text)
    openList.append(item.find_all('td')[1].text)
    highList.append(item.find_all('td')[2].text)
    lowList.append(item.find_all('td')[3].text)
    closeList.append(item.find_all('td')[4].text)
    volumeList.append(item.find_all('td')[5].text)
    MCapList.append(item.find_all('td')[6].text)

row0 =['Dates', 'Open', 'High', 'Low', 'Close', 'Volume', 'Market Capitalization' ]
    
rows = zip(dateList, openList, highList, lowList, closeList, volumeList, MCapList)

with open('bitcoinHistoricalPrice.csv', 'w', encoding='utf-8', newline='') as csvfile:
    links_writer = csv.writer(csvfile)
    links_writer.writerow(row0)
    for row in rows:
        links_writer.writerow(row)
        
# dfTable = pd.DataFrame({'Dates': dateList,'Open':openList ,'High':highList, 'Low': lowList, 'Close':closeList, 'Volume':volumeList, 'Market Capitalization': MCapList})
Trying to manipulate the data:

%matplotlib inline
import pandas as pd
import matplotlib as plt
import numpy as np
plt.rcParams['figure.figsize'] = (20.0 , 10.0)

#Read the data
data = pd.read_csv('bitcoinHistoricalPrice.csv')
print(data.shape)
data.head()

# Can't use the values because it's in string format

#Collect X and Y
X = data['Low'].values
Y = data['High'].values

#Mean X and Y
mean_x = np.mean(X)
mean_y = np.mean(Y)
Reply


Messages In This Thread
Issues with csv double quotes - by bltzr75 - Mar-23-2020, 02:00 PM
RE: Issues with csv double quotes - by snippsat - Mar-23-2020, 03:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020