我试图从不同的目录级别导入模块,所以我使用了:
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
Run Code Online (Sandbox Code Playgroud)
但现在我得到这个错误。我正在使用 Spyder,第一次使用以下导入时,它工作正常。
from source.search.ci_search_project import CI_Search_Project
Run Code Online (Sandbox Code Playgroud)
从第二次我收到这个错误开始。
文件“ipython-input-29-f35dfe634c32”,第 1 行,模块 >runfile('C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py', wdir='C:/Users/nrshakya/文档/CI/src/Comp_IntelPython')
文件“C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 880 行,在运行文件 execfile(文件名,命名空间)中
文件“C:\Users\nrshakya\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 102 行,在 execfile 中 exec(compile(f.read(), filename) , 'exec'), 命名空间)
文件“C:/Users/nrshakya/Documents/CI/src/Comp_IntelPython/ci_search_project_test.py”,第 8 行,模块 from source.search.ci_search_project import CI_Search_Project
文件“frozen importlib._bootstrap”,第 961 行,位于 _find_and_load 中
文件“frozen importlib._bootstrap”,第 946 行,位于 _find_and_load_unlocked 中
文件“frozen importlib._bootstrap”,第 885 行,位于 _find_spec 中
文件“frozen importlib._bootstrap_external”,第 1157 行,位于 find_spec 中
文件“frozen importlib._bootstrap_external”,第 1123 行,位于 _get_spec 中
文件“frozen importlib._bootstrap_external”,第 994 行,位于iter中
文件“frozen importlib._bootstrap_external”,第 982 行,在 …
我需要进行分组,然后以串联形式返回列的值。虽然我已经成功做到了这一点,但返回的数据帧的列名称为 0。只是 0。有没有办法指定结果是什么。
all_columns_grouped = all_columns.groupby(['INDEX','URL'], as_index = False)['VALUE'].apply(lambda x: ' '.join(x)).reset_index()
Run Code Online (Sandbox Code Playgroud)
生成的 groupby 对象具有标题
INDEX | URL | 0
Run Code Online (Sandbox Code Playgroud)
结果在 0 列中。虽然我已经成功地使用重命名该列
.rename(index=str, columns={0: "variant"}) this seems very in elegant.
Run Code Online (Sandbox Code Playgroud)
有什么方法可以为列提供标题吗?谢谢