我有一段非常简单的代码,在Python 3.7上运行得很顺利:
import academic_data_settings as local_settings
import pandas as pd
import glob
import os
def get_all_data():
all_files = glob.glob(os.path.join(local_settings.ACADEMIC_DATA_SOURCE_PATH, "*.csv"))
df_from_each_file = [pd.read_csv(f) for f in all_files]
concatenated_df = pd.concat(df_from_each_file, ignore_index=True)
return concatenated_df
if __name__ == "__main__":
raw_data = get_all_data()
print(raw_data)
然而,将数据可视化在pandas dataframe中是相当困难的。为了查看数据,我找到了以下文章,介绍如何直接从VSCode使用Jupyter notebook:https://devblogs.microsoft.com/python/data-science-with-python-in-visual-studio-code/。为了能够看到Python交互窗口,我需要将代码转换为jupyter代码块。
#%%
import academic_data_settings as local_settings
import pandas as pd
import glob
import os
def get_all_data():
all_files = glob.glob(os.path.join(local_settings.ACADEMIC_DATA_SOURCE_PATH, "*.csv"))
df_from_each_file = [pd.read_csv(f) for f in all_files]
concatenated_df = pd.concat(df_from_each_file, ignore_index=True)
return concatenated_df
if __name__ == "__main__":
raw_data = get_all_data()
print(raw_data)
只要我尝试运行或调试该单元格,就会在第一行出现异常:
import academic_data_settings as local_settings...
ModuleNotFoundError: No module named 'academic_data_settings'
我认为单元格评估只发送当前单元格的代码。这正确吗? 有没有办法让导入正常工作? 我不想在Jupyter笔记本中编写代码,然后将代码复制到最终将成为“生产”代码的位置。
academic_data_settings
包在哪里?当你运行 VSCode 时,它是否与主代码位于同一位置? - Lamanus