|
I'm trying to use python to make my data analysis more automated but I can't seem to find a way to use its csv module to perform operations between columns. I've got a column called "current" and a column called "voltage". I want this program to take each line of voltage and divide it by each line of current and put the resistance in a third column. I've tried both reader and dictreader methods, dictreader being easier to convert both into floats, but I can't seem to do the line by line division. I think csv might work like making an array of arrays, at least that's what I think after voltage[2] returns "l" (in non-dictreader). Anyone have experience with csv or can point me to a solution? I feel like I've looked nearly everywhere and read the documentation a hundred times already.
|
# ? Nov 17, 2013 04:32 |
|
|
# ? Jun 13, 2024 06:50 |
|
Mortimer posted:I'm trying to use python to make my data analysis more automated but I can't seem to find a way to use its csv module to perform operations between columns. You should use pandas for dealing with tables of data in python.
|
# ? Nov 17, 2013 05:09 |
|
Not going to win any beauty pageants, but it works.Python code:
|
# ? Nov 17, 2013 05:12 |
|
the, have you heard of lists? and joining them? e.g. Python code:
|
# ? Nov 17, 2013 05:46 |
|
Is there a trick to getting PyCharm professional to recognize imports properly for the purposes of warnings? 'Red warning: No module named mymodule' for each .py file I import from my own project. Yellow cannot find reference warning for many other things, such as 'Cannot find reference 'pyqtSignal' in 'QtCore.py' Most (all?) Qt objects have. I get the same message for other things, ie Python code:
Django code in HTML's also flagged. The Pycharm warnings seem great in principle, but sorting out the chaff's a pain. Dominoes fucked around with this message at 18:22 on Nov 17, 2013 |
# ? Nov 17, 2013 17:30 |
|
Dominoes posted:Is there a trick to getting PyCharm professional to recognize imports properly for the purposes of warnings? It pretty much Just Works. Sounds like you've got the project configured wrong. Are you using a virtualenv? (you better be!) Have you configured the project interpreter so PyCharm knows where to look for your modules?
|
# ? Nov 17, 2013 18:42 |
|
Double post because I'm awesome. The new OP is coming along. Posting it once more for anything further people would like in it. Don't forget you can comment right on the google doc. I started writing out examples for a bunch of the libraries and stuff, but man I'm feeling pretty lazy and that will end up being a huge job. Other things I know need some work: Some descriptions need fleshed out. Some more beginner-type information like...I mention some unit test libraries, but some info on why you should unit test might be a good idea.
|
# ? Nov 17, 2013 18:47 |
|
Thermopyle posted:It pretty much Just Works. Sounds like you've got the project configured wrong. Are you using a virtualenv? (you better be!) Have you configured the project interpreter so PyCharm knows where to look for your modules?
|
# ? Nov 17, 2013 19:03 |
|
Dominoes posted:I haven't figured out the project system; I'm just using it edit python files. What does your file structure look like? What do your import statements look like?
|
# ? Nov 17, 2013 19:10 |
|
BeefofAges posted:What does your file structure look like? What do your import statements look like? -code (I set this as PyCharm's project directory) ----myprogram --------script1.py --------script2.py Code from script1.py Python code:
Dominoes fucked around with this message at 19:38 on Nov 17, 2013 |
# ? Nov 17, 2013 19:36 |
|
Thermopyle posted:Double post because I'm awesome. Thanks for doing this, as a new to programming and new to Python goon. A lot of us newbees I'm sure realize it's a pretty big undertaking fleshing stuff out. Python is fun and I'm having fun taking it slowly and learning stuff a little at a time as a side.
|
# ? Nov 17, 2013 20:32 |
|
Fun fact: Web forms, such as when using django, use the characters '\r\n' to signify a line break. I spent hours troubleshooting a mystery issue parsing a text file with regexes from a django app, until stumbling across the answer, hidden in the bowels of stack overflow. The regex \s can find this line break, but I had to replace '\r\n' explicitly to format it properly.
|
# ? Nov 17, 2013 20:40 |
|
Dominoes posted:-code (I set this as PyCharm's project directory) if you mark "myprogram" as "Source Root" by right clicking the folder in the project explorer that will help. It's ambiguous if "code" is actually the directory for this project, or the overall project directory, which could possibly explain why pycharm needs to be taught about this (especially since you're probably using the system python instead of a virtual environment)
|
# ? Nov 17, 2013 21:40 |
|
Lurchington posted:if you mark "myprogram" as "Source Root" by right clicking the folder in the project explorer that will help.
|
# ? Nov 17, 2013 21:48 |
|
Dominoes posted:Cool, that worked for the import issue. I'm using the code directory, since I'm working on multiple projects simultaneously. I don't understand, nor at this point want to learn PyCharm's project system. I'm using it for its on-the-spot error-catching and suggestions. FYI, You literally can't use PyCharm without using projects.
|
# ? Nov 17, 2013 21:51 |
|
The project system isn't too hard. It's basically just organizing all your code together, like a folder, and making sure everything's using the same interpreter, environment, etc.
|
# ? Nov 18, 2013 15:43 |
|
For anyone who wants to try, here's the programming test I was given for a Junior Python position at a company:quote:PML Project
|
# ? Nov 18, 2013 18:27 |
|
I'm curious, were there any warnings not to use exec/eval?
|
# ? Nov 18, 2013 18:33 |
|
Lurchington posted:I'm curious, were there any warnings not to use exec/eval? No, that's the entirety of the instructions aside from "email it to us at this date blah blah."
|
# ? Nov 18, 2013 18:35 |
|
I typed up my quick solution, but instead I want to know what your solution was. Also, as I've never been paid to program, I wonder how typical that type of question is. Because that makes me feel a lot better about my prospects should I ever go looking for a Python job.
|
# ? Nov 18, 2013 18:56 |
|
I find myself using this pattern a lot for testing for numpy arrays as optional arguments. Is this the best way to do this? Python code:
|
# ? Nov 18, 2013 19:56 |
|
the posted:PML I can't be the only one who thinks this is a horrible idea, right? Aren't you not supposed to execute arbitrary Python in a webpage or something? Fake edit: Apparently that's sort of what mod_python does, but I'm still weirded out by that test. I can foresee nothing but tears coming from this.
|
# ? Nov 18, 2013 20:22 |
|
Thermopyle posted:I typed up my quick solution, but instead I want to know what your solution was. Python code:
|
# ? Nov 18, 2013 21:15 |
|
Pollyanna posted:I can't be the only one who thinks this is a horrible idea, right? Aren't you not supposed to execute arbitrary Python in a webpage or something? Browsers don't support this so-called pml tag. In fact, nothing supports it. Now, think about how this affects your questions.
|
# ? Nov 18, 2013 21:18 |
|
the posted:For anyone who wants to try, here's the programming test I was given for a Junior Python position at a company:
|
# ? Nov 18, 2013 21:27 |
|
Pollyanna posted:I can't be the only one who thinks this is a horrible idea, right? Aren't you not supposed to execute arbitrary Python in a webpage or something? Technically, this PML thing is just a template DSL like Jinja, Chameleon, or Mako. Mako in particular lets you slap arbitrary python blocks into your templates, although you're only supposed to do that for complicated presentational calculations if at all. That said, that PML thing would be pretty horrifying if it were anything other than a test question.
|
# ? Nov 18, 2013 21:33 |
|
Pollyanna posted:Fake edit: Apparently that's sort of what mod_python does, but I'm still weirded out by that test. I can foresee nothing but tears coming from this. I don't really see how pml is inherently less secure than having your browser run whatever shifty javascript code a webpage pulls in.
|
# ? Nov 18, 2013 21:34 |
|
Nippashish posted:Mod python is for running python server side, presumably this pml thing is intended to run it client side There's nothing inherently insecure or even remotely unusual about the idea of PML.
|
# ? Nov 18, 2013 21:38 |
|
It's obviously test to see if you can write (or use) a parser and do a trivial task with the result, not of best practices in system architecture.
|
# ? Nov 18, 2013 21:48 |
|
the posted:The only issue is that my code doesn't handle the initial indent after the <pml> tag in their example code, which seems totally pointless. If I remove the initial indent the code runs fine and it doesn't affect the look much at all. Your code won't handle multiple PML blocks according to the spec. code:
code:
|
# ? Nov 18, 2013 21:52 |
|
Pollyanna posted:I can't be the only one who thinks this is a horrible idea, right? Aren't you not supposed to execute arbitrary Python in a webpage or something? this is one of the main criticisms against the cheetah templating engine too the fact that you're appending to the same file and executing it multiple times, with exec file means that you can end up with weirdness on the offchance they write out pml that has side effects along with it. for example, in the intentionally bad code: code:
I guess what I'm saying is that execfile will put things in your modules globals(), and the fact that you're re-executing code via append seems bad. also, my preferred way to mess with this code: code:
|
# ? Nov 18, 2013 21:53 |
|
Oh, well. Hopefully they see past that. They said they intentionally gave me something "I wasn't familiar with," knowing that I come from a background of numerical computation, etc.
|
# ? Nov 18, 2013 22:47 |
|
You are glorious, thank you very much. Worked perfectly. And I'm definitely going to learn pandas.
|
# ? Nov 18, 2013 23:39 |
|
There's nothing more insecure about this PML thingy than with, say Django's templating system. Browsers can't do anything with it, so it would only be used on the server side. The only thing that can do anything with it is whatever server side tools the company would use to generate HTML with it, and that's exactly the case with any other templating thing. Of course, it's just a test question, but this was brought up by this: Pollyanna posted:I can't be the only one who thinks this is a horrible idea, right? Aren't you not supposed to execute arbitrary Python in a webpage or something? In other words, PML would be exactly as secure as any other dynamically generated website on the internet.
|
# ? Nov 18, 2013 23:54 |
|
Thermopyle posted:There's nothing more insecure about this PML thingy than with, say Django's templating system. Well, except that most template engines offer automatic HTML escaping.
|
# ? Nov 19, 2013 00:03 |
|
Thermopyle posted:Browsers don't support this so-called pml tag. In fact, nothing supports it. Which is why this is so to me. What is even the point of this test? Why?
|
# ? Nov 19, 2013 00:10 |
|
Pollyanna posted:Which is why this is so to me. What is even the point of this test? Why? To see if someone can follow basic instructions and has a minimum level of competence.
|
# ? Nov 19, 2013 00:12 |
|
"What? Why would anybody want a tool that prints Fizz, Buzz, or Fizzbuzz?!?!?"
|
# ? Nov 19, 2013 00:13 |
|
Pollyanna posted:Which is why this is so to me. What is even the point of this test? Why? Well, that's not what you questioned originally. Your original objection was that you're not supposed to execute Python in a web page....and that's not what this does. fritz covered as to why this would be in an interview.
|
# ? Nov 19, 2013 00:28 |
|
|
# ? Jun 13, 2024 06:50 |
|
Thermopyle posted:There's nothing more insecure about this PML thingy than with, say Django's templating system. Someone way smarter than me posted:Imagine you have a file upload form that dumps files into some public directory. To make sure nobody uploads PML files, you just check that they don’t have a .pml extension. All an attacker has to do is upload a file named foo.pml.txt; your uploader won’t see a problem, but Apache will recognize it as PML, and it will happily execute.
|
# ? Nov 19, 2013 01:53 |