目前,我正在使用 for 循环从文件夹中读取 csv 文件。读取 csv 文件后,我将数据存储到字典的一行中。当我使用“print(list_of_dfs.dtypes)”打印数据类型时,我收到:
dtype:对象 DATETIME:对象 值:float64 ID:int64 ID 名称:对象。
请注意,这是一个嵌套字典,其中每个数据字段中存储了数千个值。我有上面列出的 26 行结构。我正在尝试将字典行附加到数据框中,其中只有 1 行由数据字段组成:
索引日期时间值 ID ID 名称。
注意:我正在学习Python。我尝试使用数组来存储数据,然后将数组转换为数据帧,但无法附加数据帧的行。
使用字典方法我尝试“df = pd.Dataframe(list_of_dfs)”这会引发错误。
list_of_dfs = {}
for I in range(0,len(regionLoadArray)
list_of_dfs[I] = pd.read_csv(regionLoadArray[I])
#regionLoadArray contains my- file names from list directory.
dataframe = pd.DataFrame(list_of_dfs)
#this method was suggested at thispoint.com for nested dictionaries.
#This is where my error occurs^
Run Code Online (Sandbox Code Playgroud)
ValueError:如果使用所有标量值,则必须传递索引
感谢您对这个问题的任何帮助,因为我是 python 新手。我当前的目标是简单地生成一个带有标题的数据框,然后将其发送到 csv。
我正在尝试在安装了其他 Python 的 CentOS 7 多用户系统上从源代码构建 Python 2.7。我最初是用 gcc 6.3.0 构建 Python 2.7.15 并带有以下标志:
./configure --prefix=/path/to/install --enable-shared --enable-optimizations
Run Code Online (Sandbox Code Playgroud)
在遇到一些构建错误后,我尝试了:
./configure --prefix=/path/to/install --enable-shared --enable-optimizations --with-ensurepip --enable-unicode=ucs4
Run Code Online (Sandbox Code Playgroud)
我遇到了两个主要错误。首先,我过去只将 PYTHONPATH 设置为顶级 lib 目录。例如:PYTHONPATH=/path/to/python/lib/python2.7 使用这个构建 python 无法在 lib-dynload 中找到模块,除非我设置 PYTHONPATH=/path/to/python/lib/python2.7:/path/to /python/lib/python2.7/lib-dynload 第二个问题是(在将 PYTHONPATH 设置为包含 lib-dynload 之后)当我尝试运行 pip 时,我从weakref.py收到以下错误:ImportError: cannot import name _remove_dead_weakref I不确定其他模块有哪些错误,但如果这不是与 weakref.py 隔离,我不会感到惊讶
我尝试了以下修改:
请不要回复不包括从源代码构建的解决方案
更新
我进入了提交历史,看看我是否能找到添加了“_remove_dead_weakrefs”的版本。Python 2.7.14 是第一个带有此代码的版本,Python 2.7.13 没有它。
我能够在我的系统上编译 2.7.13,现在可以在 python 中导入 weakref 允许我运行 pip。此外,我不必将 PYTHONPATH 指向 lib-dynload …
python ×2
build ×1
centos ×1
centos7 ×1
dataframe ×1
dictionary ×1
excel ×1
pandas ×1
python-2.7 ×1