readfile

Is it possible to read categorical columns with pandas' read_csv?

随声附和 提交于 2019-11-30 08:08:34
I have tried passing the dtype parameter with read_csv as dtype={n: pandas.Categorical} but this does not work properly (the result is an Object). The manual is unclear . In version 0.19.0 you can use parameter dtype='category' in read_csv : data = 'col1,col2,col3\na,b,1\na,b,2\nc,d,3' df = pd.read_csv(pd.compat.StringIO(data), dtype='category') print (df) col1 col2 col3 0 a b 1 1 a b 2 2 c d 3 print (df.dtypes) col1 category col2 category col3 category dtype: object If want specify column for category use dtype with dictionary: df = pd.read_csv(pd.compat.StringIO(data), dtype={'col1':

Read data from a text file and create an object

為{幸葍}努か 提交于 2019-11-30 07:45:11
I need some help: I'm making a Supermarket simulation on Java, but I've got one problem, I have a text file (Stock.txt) where I have all the supermarket stock on it for example: 0-Bakery-Chocolate Cake-$12.5-250 1-Meat-Premium Steak-$2.6-120 2-Seafood-Tuna - $1.2-14 ... Where the first number is the "id" for the product, next is the department the product belongs, third is the name of the product, the next thing is the price, and the last number is how much pieces of the product the stock has. I have this class: public class Product { protected String name; protected double price; protected

readFileSync is not a function

ぃ、小莉子 提交于 2019-11-30 06:07:05
I am relatively new to Node.js and have been looking around but cannot find a solution. I did check the require javascript file and it does not seem to have a method for "readFileSync". Perhaps I don't have a proper require file? I had a hard time finding this file, everywhere talked about it but most people did not post where to get it. I installed Node.js and have the require.js file. My current code is like this: fs = require(['require'], function (foo) { //foo is now loaded. }); console.log("\n *STARTING* \n"); // Get content from file var contents = fs.readFileSync("sliderImages", 'utf8')

Win32 ReadFile hangs when reading from pipe

泄露秘密 提交于 2019-11-30 05:01:43
问题 I am creating a child process, and reading its output. My code works fine when the child process creates output ( cmd /c echo Hello World ), however ReadFile will hang if process does not create output ( cmd /c echo Hello World > output.txt ). I am only reading after the process has terminated. Am I doing something horribly wrong? Is there anyway to do this with synchronous mode, or do I have to use asynchronous mode? All of this is happening in a seperate thread, so I dont think asynchronous

Unable to parse as integer

拈花ヽ惹草 提交于 2019-11-30 04:34:25
问题 Alright...I have this .txt file (UTF-8) 4661,SOMETHING,3858884120607,24,24.09 4659,SOMETHING1,3858884120621,24,15.95 4660,SOMETHING2,3858884120614,24,19.58 And this code FileInputStream fis = new FileInputStream(new File(someTextFile.txt)); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); BufferedReader in = new BufferedReader(isr); int i = 0; String line; while((line = in.readLine()) != null) { Pattern p = Pattern.compile(","); String[] article = p.split(line); // I don't know

Node.js from fs.readFileSync() to fs.readFile()

99封情书 提交于 2019-11-30 01:14:09
I'm trying to get my head around synchronous vs asynchronous in Node.js, in particular for reading an html file. In a request handler, the synchronous version that i'm using, which works is the following: var fs = require("fs"); var filename = "./index.html"; var buf = fs.readFileSync(filename, "utf8"); function start(resp) { resp.writeHead(200, {"Content-type":"text/html"}); resp.write(buf); resp.end(); } exports.start=start; What would be the version using readFile() ?? I understand that readFile is asynchronous so theoretically I should wait that the entire file is read before rendering it,

ReadFile in Base64 Nodejs

亡梦爱人 提交于 2019-11-29 22:52:13
I'm trying to read an image from client side encoded in base64. How to read with nodejs? My code: // add to buffer base64 image var encondedImage = new Buffer(image.name, 'base64'); fs.readFile(encondedImage, "base64", function(err, buffer){ if ( err ) { console.log('In read file') console.log(err) } else { // check err lwip.open(buffer, 'jpg', function(err, image){ console.log('in open') if ( err ) console.log(err) if ( image ) console.log(image) // check 'err'. use 'image'. // image.resize(...), etc. }); } }) But, I got this error: In read file [Error: Path must be a string without null

Open file in ML(SMLNJ)

不羁岁月 提交于 2019-11-29 18:11:44
I need to read file in ML (SLMNJ) and save it in some structures. I need to read some data that points to graph declaration: [( 1 , 2 , 13 ),( 2 , 3 , 3 ),( 2 , 4 , 8 ),( 2 , 5 , 4 ),( 3 , 1 , 5 ),( 3 , 4 , 1 ),( 4 , 6 , 5 ),( 5 , 5 , 5 ),( 6 , 4 , 6 )] (first number: name of the node , secend number: name of connected node , third number weight for this mane (each () show one mane ) ) for expamle this is test input how to read file and which structure to save it for reading from file follow this to list of string per line : val infile = "c:/input.txt" ; fun readlist (infile : string) = let

No such file or directory while trying to read files in a directory python

隐身守侯 提交于 2019-11-29 17:26:06
I have this code which lists the files in the directory and parses each one of them with my function. paths = [] for filename in os.listdir(r"C:\Program Files (x86)\Folder\Folder"): with open(filename) as f: paths.append(parse_file(f)) I am getting the error: File "find.py", line 21, in <module> with open(filename) as f: IOError: [Errno 2] No such file or directory: 'file.txt' This error shows that it saw file.txt because it exist in the folder I specified in os.listdir , I have many more files there. If I delete file.txt it will show the error on a different file. I also tried to move the

PHP Readfile() not working for me and I don't know why

我的梦境 提交于 2019-11-29 16:41:45
I am trying to get this code to work but for some reason, all the echo's are able to output correct content, but the headers don't seem to want to force the download of my document. What follows is the file I am trying to build for file downloads. It is set to input code like this: downloader.php?f=13&t=doc to download a file that is named 201-xxx.doc or 201-xxx.pdf from one of two folders depending on the users privileges. All the logic works up to the header info at the bottom. If I comment out the header content type and the header content disposition, then it will read the file into the