import-from-csv

Cannot import data from csv file in d3

送分小仙女□ 提交于 2019-11-26 21:15:52
问题 I'm just learning d3, and I'm attempting to import data from a CSV file, but I keep getting the error "XMLHttpRequest cannot load file:///Users/Laura/Desktop/SampleECG.csv. Cross origin requests are only supported for HTTP. ". I've searched for how to fix this error and have ran it on a local web server, but I haven't found a solution that works for d3.v2.js. Here's a sample of the code: var Time = [] ECG1 = [] d3.csv("/Desktop/d3Project/Sample.csv", function(data) { Time = data.map(function

Read a small random sample from a big CSV file into a Python data frame

一世执手 提交于 2019-11-26 09:27:48
问题 The CSV file that I want to read does not fit into main memory. How can I read a few (~10K) random lines of it and do some simple statistics on the selected data frame? 回答1: Assuming no header in the CSV file: import pandas import random n = 1000000 #number of records in file s = 10000 #desired sample size filename = "data.txt" skip = sorted(random.sample(xrange(n),n-s)) df = pandas.read_csv(filename, skiprows=skip) would be better if read_csv had a keeprows, or if skiprows took a callback