|
It seems like Pandas just making numpy behave like data frames from R or tables from Matlab. Is that the basic idea or is there more to it?
|
# ¿ Jul 21, 2014 16:50 |
|
|
# ¿ Apr 27, 2024 06:42 |
|
rock2much posted:I did this! Just work through the problems on Project Euler.
|
# ¿ Jul 21, 2014 21:40 |
|
Is there a canonical way to get a column vector in numpy? The obvious a.T doesn't work on a normal vector. If I want to get a 1-5 multiplication table in Matlab I can do:code:
code:
There's obviously a bunch of ways to do this: code:
|
# ¿ Jul 22, 2014 22:39 |
|
Symbolic Butt posted:You can use the outer product, that's what I use when I need something like that: np.outer(a, a) Well, there are other times when column vectors are useful I would think, unless there's some other more pythonic structure I don't know about. Say I have a 3x2 matrix M and want to add a third column that's a linear combination of the first two. In Matlab I can do: code:
Python code:
|
# ¿ Jul 23, 2014 22:22 |
|
Reformed Pissboy posted:Nothing wrong with this approach, but you don't need to iterate over string.printable -- i in string.printable without the for will evaluate as "does string.printable contain i?" What's wrong with list comprehension approach? Python code:
|
# ¿ Jul 24, 2014 19:01 |
|
QuarkJets posted:PEP 8 disagrees You can use a lambda function inline without assigning it. PEP8 is fine with that usage. edit: By which I mean: Python code:
KernelSlanders fucked around with this message at 21:37 on Jul 24, 2014 |
# ¿ Jul 24, 2014 21:30 |
|
Crosscontaminant posted:The standard library (e.g. operator) provides useful functions like itemgetter for use as key functions and with map/reduce, so there should be no need for a lambda for anything this simplistic. If it's more complex, give it a name and documentation so people who come after you know what the hell you're doing and can use it elsewhere without having to refactor. How is map(operator.pow, my_list, [2]*len(my_list)) more readable? Or are you suggesting something else?
|
# ¿ Jul 24, 2014 23:08 |
|
floppo posted:apologies if this is too broad a question for this thread. I am interested getting data from twitter - specifically a list of all the people following a specific account. My goal is compare two such lists and see who is connected to who - this would require a second set of queries. I assume this isn't some money-making venture and you're doing this to gain some experience from the project. In that case, the most valuable skill you will get out of a project like that is the ability to make sense of API docs and build a compliant interface to them. I would strongly suggest you just give it a try. If you're completely lost, the best first hint I can give is that the API will work by you formatting URLs a certain way (as described in the docs) and making web requests with them. The web service will reply with a text document with the data you want in a format also described in the docs. I strongly suggest, you start by just trying to get something (anything) from the API and build from there. I've done some twitter integration before, so if you get stuck come back or shoot me a PM. If you don't care about learning how to do it, there is a module called python-twitter that may help, but I haven't really played with it.
|
# ¿ Aug 11, 2014 17:25 |
|
ShadowHawk posted:
I always hated questions like that because there are so many possible answers and I never know what they're looking for. Are you trying to show how you're competent to write professional code rather than homework assignments? Use the library. Do you know how to solve basic programming problems? Write a legible homework-style function with superfluous comments. Do you really know the ins and outs of the platform? Do something like ShadowHawk. It's a bit like that old Google interview question of, "On a new hardware platform, how would you determine if the stack grows up or down in memory?" I always thought the answer should be, "Read the documentation." Anyone writing code to solve that one is tunnel-visioning and just wasting company time. Of course, I don't work for Google, so what do I know.
|
# ¿ Aug 11, 2014 19:16 |
|
QuarkJets posted:Is this MySQLdb or something else? For whatever reason I never have to use commit() with MySQLdb Depending on whether you're using MyISAM or InnoDB, MySQL may not support transactions. It's also possible on InnoDB to set autocommit on.
|
# ¿ Aug 13, 2014 01:11 |
|
You can also open a terminal, navigate to the PyCharm project directory, and run the script from the command line there.
|
# ¿ Aug 16, 2014 16:38 |
|
Is there a good way to filter on a list of tuples? For example, let's say I want to sum the second values where something about the first value is true. This can be done with a list comprehension, but feels a little clunky.Python code:
Python code:
|
# ¿ Aug 17, 2014 18:13 |
|
Symbolic Butt posted:Your example is kind of odd, why can't you use a dictionary? Or even something like this: Because my_list is the output of a library function that returns a list of tuples. I have no idea why it does this rather than returning a dictionary. Also, the fact that the second values of my tuples were 1,2,3,4 was just a poor choice in setting up my example and could be anything. I do think your tuple expansion combined with ShadowHawk's point about using the generator leads to something pretty clean. Python code:
KernelSlanders fucked around with this message at 20:17 on Aug 17, 2014 |
# ¿ Aug 17, 2014 20:14 |
|
dirtycajun posted:Okay I made the changes, turns out I did need the break, and it would only work if I did another time call in the inner loop. It can probably get cleaned up some but this functions: If your plan is to leave it running until you CTRL-C the process from the terminal, you should probably look into trapping signals so that you can shut the light off right before your application quits.
|
# ¿ Aug 24, 2014 14:59 |
|
BigRedDot posted:Oh, I do too, hence the scare quotes. Let's go another direction and make the ultra-flexible enterprise scorer that can perform arbitrary accumulations and transforms on the input with configurable decoders: Let's take a simple problem and rather than taking five minutes to solve it, let's figure out if it's a special case of some much larger set of problems that we might possibly (but probably won't) want to solve at some point in the future. Then let's develop a spec for an extensible framework and class library that can be called upon to solve any of those larger classes of problems using unnecessarily cryptic chains of method calls to execute the same functionality as we could have done yesterday when we started all this. Sorry, but solving a problem that can be solved in 20 lines of code (unless it's running a space shuttle or pacemaker) shouldn't involve opening powerpoint to make a presentation on your proposed "framework." This is why I hate java.
|
# ¿ Sep 2, 2014 03:48 |
|
Steampunk Hitler posted:Now I want to be able to drop the installer_version however since there are multiple values there, I'd like to take any row where the only difference is the installer_version column, and sum() the count column. Anyone have an inkling how to do this? It should be Python code:
Python code:
KernelSlanders fucked around with this message at 16:18 on Sep 9, 2014 |
# ¿ Sep 9, 2014 14:37 |
|
Hughmoris posted:Let me preface this by saying I'm not a programmer, just a guy trying to automate crap at work... Start by reading the entire file list into memory, parse the start and end date parts of the filename into datetime objects, then find the ones that overlap your target date. Hint: ranges that overlap your target date are the ones where the start date is less than or equal to your target and the end date is greater than or equal to your target. That kind of indexing is the sort of thing pandas does really cleanly, but it can certainly be done just using lists as well.
|
# ¿ Sep 10, 2014 13:38 |
|
Just chiming in to echo that HTMLParser is amazing and you should use it. e: ^^ BeutifulSoup is also very nice, although they are quite different in the way you use them.
|
# ¿ Sep 18, 2014 03:24 |
|
kraftwerk singles posted:I'm having a strange issue rounding numbers in pandas and exporting to dict. This appears to be working as intended. You told python you only cared about two decimal places and then complained when the 18th decimal place wasn't what you expected. Basically, when you call round on 0.081347309478284627, you're asking for a number that is indistinguishable from 0.08 within floating point precision. That is exactly what you got. The problem is, 0.08 cannot be specified exactly in binary just like 1/3 cannot be specified exactly in decimal. Try subtracting 0.08 from 0.080000000000000002, you should get 0 not 2E-12. If you want number represented exactly to two decimal places, use a decimal class.
|
# ¿ Sep 18, 2014 20:57 |
|
SurgicalOntologist posted:The problem is that out.append(i) modifies out in-place and returns None. In a comprehension, you need to use the value itself. There's also the numpy.unique function.
|
# ¿ Sep 22, 2014 18:05 |
|
Cultural Imperial posted:Another vote for pycharm, Mac or PC. 4
|
# ¿ Sep 23, 2014 02:22 |
|
regularizer posted:Gotcha, thanks. I was trying to learn list comprehensions before the tutorial got to it. On a related note, when I finish the codecademy tutorial in a few days what should I do next? I'd like to get a more in-depth understanding of python before moving on to another language. I was thinking about trying to make a simple program I could run on osx, so is there something I could do to learn about making GUIs with python? The answer to that depends entirely on why you are learning python. If it's to have fun, then pick something (simple, always start simple) that you think would be fun to try to build it. It really doesn't matter what it is. If you're learning python to get a job, then it depends on what kind of job: general developer, web developer, front-end developer, data scientist all suggest different classes of projects you should try.
|
# ¿ Sep 23, 2014 22:35 |
|
EAT THE EGGS RICOLA posted:PyCharm. This should probably just get added to the OP at this point.
|
# ¿ Oct 8, 2014 22:32 |
|
Thermopyle posted:I just wanted to stop in and say that I've been using mypy for the last week (I've just played with it previously) and it's pretty super if you've thought that Python could use option static type checking. It's an interesting idea, but seems to go against a lot of pythonic practices, especially the centrality of the dict or list with non-uniform types. Dominoes posted:I like how the type signatures provide a quick insight of what the function's doing. It's especially useful when inputting or outputting complex/nested data structures. While that can be a plus when things are not otherwise well documented, but it doesn't replace proper documentation. I've been doing a fair bit of scala programming lately and it's amazing how many library authors think "type safe" means "don't have to write documentation."
|
# ¿ Jan 9, 2015 04:07 |
|
You seem to have a circular dependency.
|
# ¿ Jan 9, 2015 04:23 |
|
SurgicalOntologist posted:Given this spec for communicating with a treadmill over serial, what data type should I be sending? I've never done this kind of thing before. I thought it should be b'C0' for example, but that doesn't work. Do I need to do some kind of encoding? I'm a bit out of my element here. Is that all the spec you have? It looks like not really enough. They should also provide you the unit's desired baud rate and parity settings. To test the communication, you should be able to write 0xA4 and read out 0xB4. Python code:
|
# ¿ Aug 13, 2015 13:58 |
|
SurgicalOntologist posted:Figured out the bytes thing. It had to be dev.write([0xA1]) (i.e. it expected an iterable). Yeah that makes sense. Glad you got it working.
|
# ¿ Aug 14, 2015 02:45 |
|
What's wrong with the comprehension here? It seems pretty clean.
|
# ¿ Oct 24, 2015 22:09 |
|
The operator and is the builtin logical operator you should probably be using unless you're dealing with numpy arrays. For the loop, you could pre-filter with a generator or list comprehension, although I don't know that it's any clearer than your second example. Python code:
Python code:
|
# ¿ Oct 27, 2015 14:22 |
|
SurgicalOntologist posted:Is it possible to remove the leading zero when string formatting a float guaranteed to be between -1 and 1? I always look into this when I'm annotating correlations, and I always give up and do it in two steps. Now, though, I'm using a library that has you pass in the formatting string... so am I out of luck? When all else fails, regex. Python code:
|
# ¿ Oct 30, 2015 05:57 |
|
If not for the downward only constraint the longest path is any of the many possibilities that touch every node. For the downward only version, why wouldn't you just start at the bottom and work back to the top? For the row one up from the bottom, each node is worth its weight plus the greater of the two below it. Assign that as the new weight for the node and repeat for the row above. O(n)
|
# ¿ Nov 12, 2015 06:23 |
|
Dominoes posted:Is there a way to make Pycharm stop weak-warning uppercase variable names? Unlike some inspections, the only alt-enter option is to rename the variable. I can't find a suitable error code to ignore on this page. I can disable the pep8 naming convention inspection, but that's broader than I'd like. The easiest way, of course, is to use PEP8 compliant variable names.
|
# ¿ Dec 30, 2015 23:47 |
|
Dominoes posted:Scientific programming makes sense with uppercase variable names (including things like Δ) when convention calls for them. Popular libraries like scikit learn use them in documentation. I'm not sure that arguing you want unicode variable names is much of an improvement. I don't follow your point about sklearn. Are you saying that there is code in an sklearn docstring that doesn't follow sklearn coding standards?
|
# ¿ Dec 31, 2015 05:52 |
|
Symbolic Butt posted:idk writing simply dt is a super old convention in scientific programming, graphics programming, maybe even programming in general I'd say Yeah, changing to δt kind of misses the point. What's wrong with dt or deltaT?
|
# ¿ Dec 31, 2015 16:31 |
|
Er... delta_t I mean.
|
# ¿ Dec 31, 2015 17:39 |
|
SurgicalOntologist posted:If you're on OSX you can also do os.system('say X') which can be a lot of fun. This is amazing. Thank you. I can now annoy the hell out of my office mates. e: Holy poo poo git log 2>&1 | say -f - KernelSlanders fucked around with this message at 18:48 on Jan 24, 2016 |
# ¿ Jan 24, 2016 18:45 |
|
Lysidas posted:Some tools on Windows (like Notepad, as I recall) prepend U+FEFF to files before saving as UTF-8. Though this doesn't function as a byte order mark (since the concept of byte order doesn't apply to UTF-8), it's still technically valid and serves as a marker that "this file is definitely UTF-8 content". I'm continually amazed how Windows manages to mangle files. We bought some Bing search ads and hooked up our normal analytics pipeline to their API to download some CSVs that say how the ads did. Care to guess how it broke?
|
# ¿ Feb 22, 2016 06:29 |
|
qntm posted:Line endings? Yup. Even if you work at Microsoft, who sits down to write a web endpoint and thinks CR LF termination is a good idea?
|
# ¿ Feb 22, 2016 15:34 |
|
Hammerite posted:Wikipedia says... "Most textual Internet protocols (including HTTP, SMTP, FTP, IRC, and many others) mandate the use of ASCII CR+LF ('\r\n', 0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF ('\n', 0x0A) as well." I'm not sure whether you were downloading files rather than making web requests, but it seems to me that in that case Microsoft are quite entitled to send you CR+LF files, and if you don't account for that possibility then that's your bag. Downloading files.
|
# ¿ Feb 25, 2016 14:45 |
|
|
# ¿ Apr 27, 2024 06:42 |
|
Is there a stupid simple unconstrained non-linear solver for python similar to Matlab's fminunc?
|
# ¿ Mar 28, 2016 05:01 |