1

最近,为了我在 PyCharm IDE 中创建的一个特定项目,我安装了 pandas_profiling。它在“设置”中更新了“外部工具”后工作。在另一个项目上下文中实现了类似的需求,我也在该特定项目的 ...\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
4

0 回答 0