python - 试图用 Pandas 中的列名获取列索引

标签 python pandas jupyter-notebook

我正在做一个带有嵌入式 jupyter notebook 的项目,当我打开 df.info() 时,它没有标题,也没有索引号。我尝试执行 df.info(verbose=True) 但仍然没有执行。在我的桌面上,当我执行 df.info() 时,它的列标题显示:#、列、非空计数和 dtype。我只是想获取每个列名及其相应索引值的列表。有更好的方法吗?

我想看到它

0 列 1 名称 1 Column2Name ...等

最佳答案

i = 0
for col in df.columns:
    print(i, col)
    i += 1

关于python - 试图用 Pandas 中的列名获取列索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63320053/

相关文章:

python - Pandas reshape 宽到长返回零结果

python - 在 ipython notebook 中使用 pandas dataframe map 函数时出错

python - ipykernel(Jupyter 笔记本/实验室)无法从 traitlets.utils 导入名称 '' filefind”

Python多维符号自动转置

python - 删除外键

python - reshape Pandas DataFrame : switch columns to indices and repeated values as columns

python - 使用条件语句返回数据帧的子集

python - 如何在 Jupyter notebook (iPython) 中并排显示 2 张图像?

python - 从列表中删除无法转换为集合的重复项

python - 为什么 Python 在 numpy 数组切片上循环比完全矢量化操作更快