naming

Creating custom names for columns based on other column names in pandas dataframe

Creating custom names for columns based on other column names in pandas dataframe Question: I have a dataframe like below: I am looking to create a column using difference or use any other calculations among columns. However, I looking to name the column so that it relfects the operation done. For ex below I am …

Total answers: 3

Python official name for an attribute that is not a method

Python official name for an attribute that is not a method Question: According to my understanding the data members of objects in Python are referred to as ‘attributes’. Attributes that are callable are referred to as an object’s ‘methods’, but I couldn’t find a name for non-callable attributes, such as val in the following example: …

Total answers: 2

Python creating variables with names from range

Python creating variables with names from range Question: I want to use some code similar to what follows that actually works: P = 20 n = 1 for x in range(1, P+1): Ax = n #Hoping that you can name the variable from the current element in the range n = n+1 I want to …

Total answers: 3

Open file knowing only a part of its name

Open file knowing only a part of its name Question: I’m currently reading a file and importing the data in it with the line: # Read data from file. data = np.loadtxt(join(mypath, ‘file.data’), unpack=True) where the variable mypath is known. The issue is that the file file.data will change with time assuming names like: file_3453453.data …

Total answers: 4

Python "private" function coding convention

Python "private" function coding convention Question: When writing a python module and functions in it, I have some “public” functions that are supposed to be exposed to outsiders, but some other “private” functions that are only supposed to be seen and used locally and internally. I understand in python there is no absolute private functions. …

Total answers: 1

Why are underscores better than hyphens for file names?

Why are underscores better than hyphens for file names? Question: From Building Skills in Python: A file name like exercise_1.py is better than the name exercise-1.py. We can run both programs equally well from the command line, but the name with the hyphen limits our ability to write larger and more sophisticated programs. Why is …

Total answers: 2

Is it ok to use dashes in Python files when trying to import them?

Is it ok to use dashes in Python files when trying to import them? Question: Basically when I have a python file like: python-code.py and use: import (python-code) the interpreter gives me syntax error. Any ideas on how to fix it? Are dashes illegal in python file names? Asked By: Joan Venge || Source Answers: …

Total answers: 7