Here is my code to generate a dataframe: then I got the dataframe: When I type the commmand : I got : According to the reference of pandas, axis=1 stands for columns and I expect the result of the command to be So here is my question: what does axis in pandas mean? Answer It specifies the axis along which
Tag: python
How to connect to Mongo database locally using python
I am using ipython 2.7. I am creating database name enron in mongodb. I have tried to connect to this database locally but the following error occurred – how do I fix it? this my code: error: Answer Refer this PyMongo Connection to connect and Connection is deprecated
Python – how to overwrite output from Markdown library
I have following problem, i’m using markdown library for my webapp and i need to modify the output generated by it, namely i want to change default <img src=”…”> tag into <img data-src=”…”>. What would be the best way to change the html generated by this m…
Wrapping around on a list when list index is out of range
I’m looking for some code improvement, or a pre-built version of what I’ve implemented myself as I think there might be, or should be, a cleaner way to achieve what I want. I’m writing a piece of software to convert guitar tabs into classical notation, I need to convert the number on a tab t…
Difference between numpy.array shape (R, 1) and (R,)
In numpy, some of the operations return in shape (R, 1) but some return (R,). This will make matrix multiplication more tedious since explicit reshape is required. For example, given a matrix M, if we want to do numpy.dot(M[:,0], numpy.ones((1, R))) where R is the number of rows (of course, the same issue als…
Problems Installing Python igraph
I installed the igraph python library using pip I go on the Python console/terminal and import the module No problem. Then I test to see the version number No problem there either. But when I try to create a script. And execute or All i get is Answer Try this, as your script: Global imports are generally not …
Fast hash for strings
I have a set of ASCII strings, let’s say they are file paths. They could be both short and quite long. I’m looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids: MD5 seems to be what I need, bu…
Improving Python NetworkX graph layout
I am having some problems in visualizing the graphs created with python-networkx, I want to able to reduce clutter and regulate the distance between the nodes (I have also tried spring_layout, it just lays out the nodes in an elliptical fashion). Please advise. Parts of code: Answer In networkx, it’s wo…
Timeout for python requests.get entire response
I’m gathering statistics on a list of websites and I’m using requests for it for simplicity. Here is my code: Now, I want requests.get to timeout after 10 seconds so the loop doesn’t get stuck. This question has been of interest before too but none of the answers are clean. I hear that maybe…
NumPy dtype issues in genfromtxt(), reads string in as bytestring
I want to read in a standard-ascii csv file into numpy, which consists of floats and strings. E.g., Whatever I tried, the resulting array would look like E.g., However, I want to save a step for the byte-string conversion and was wondering how I can read in the string columns as regular string directly. I tri…