在一个Pycharm项目中如何运行同一个py文件,而在另一个项目中却运行不了,而两个项目都导入了相同的模块

时间:2019-10-07 19:35:01

标签: pandas-profiling

最近,我安装了pandas_profiling,用于在PyCharm IDE中创建的特定项目。在“设置”中更新了“外部工具”后,该工具才起作用。在另一个项目上下文中实现类似的需求时,我也在该特定项目的…\ venv \ Scripts路径中安装了pandas_profiling。在新项目中对外部工具进行了类似的更新。但是控制台不断告诉我它无法检测到模块。当我检查时,两个项目的“站点软件包”和“ venv”目录中都有pandas_profiling软件包文件。有什么想法吗?谢谢您的支持。

from pathlib import Path

import pandas as pd
import numpy as np
import requests

import pandas_profiling

if __name__ == "__main__":
    file_name = Path("C:\\Users\…..csv")
if not file_name.exists():
    data = requests.get(
        "C:\\Users\…..csv"
         )
        file_name.write_bytes(data.content)

    df = pd.read_csv(file_name)
    df["Feature_1"] = pd.to_datetime(df["Feature_1"], errors="coerce")

    # Example: Constant variable
    # df["source"] = "name of org"

    # Example: Boolean variable
    df["boolean"] = np.random.choice([True, False], df.shape[0])

    # Example: Mixed with base types
    df["mixed"] = np.random.choice([1, "A"], df.shape[0])

    # Example: Highly correlated variables
    df["Feature_2"] = df["Feature_2"] + np.random.normal(scale=5, size=(len(df)))

    # Example: Duplicate observations
    duplicates_to_add = pd.DataFrame(df.iloc[0:10])
    duplicates_to_add[u"Feature_1"] = duplicates_to_add[u"Feature_1"]

    df = df.append(duplicates_to_add, ignore_index=True)

    profile = df.profile_report(
    title="Report", correlation_overrides=["recclass"]
    )
    profile.to_file(output_file=Path("C:\\Users.....html"))

在新项目中(在现有项目中工作时)从控制台进行响应:

Traceback (most recent call last):
  File "C:/Users/.../PycharmProjects/.../Pandas_Profiling_2.py", line 8, in <module>
    import pandas_profiling
ModuleNotFoundError: No module named 'pandas_profiling'

Process finished with exit code 1

0 个答案:

没有答案