Skip to content

Tag: python

What does axis in pandas mean?

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

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…

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…