Merging two DataFrames

The error message indicates that df2 is of type pd.Series. You need to convert df2 .to_frame() as .merge() needs a pd.DataFrame() input (see docs): while you probably also just could: Alternatively, you can use pd.DataFrame.join() which accepts a pd.Series.

Purpose of #!/usr/bin/python3 shebang

#!/usr/bin/python3 is a shebang line. A shebang line defines where the interpreter is located. In this case, the python3 interpreter is located in /usr/bin/python3. A shebang line could also be a bash, ruby, perl or any other scripting languages’ interpreter, for example: #!/bin/bash. Without the shebang line, the operating system does not know it’s a python script, even if you set the execution flag (chmod … Read more

print(__doc__) in Python 3 script

it seems __doc__ is useful to provide some documentation in, say, functions This is true. In addition to functions, documentation can also be provided in modules. So, if you have a file named mymodule.py like this: You can access its docstrings like this: Now, back to your question: what does print(__doc__) do? Simply put: it prints the module docstring. If no … Read more

Difference between data type ‘datetime64[ns]’ and ‘

datetime64[ns] is a general dtype, while <M8[ns] is a specific dtype. General dtypes map to specific dtypes, but may be different from one installation of NumPy to the next. On a machine whose byte order is little endian, there is no difference between np.dtype(‘datetime64[ns]’) and np.dtype(‘<M8[ns]’): However, on a big endian machine, np.dtype(‘datetime64[ns]’) would equal np.dtype(‘>M8[ns]’). So datetime64[ns] maps to either <M8[ns] or >M8[ns] depending on the endian-ness of the … Read more