Python Pandas read_csv保持列顺序 [英] Python Pandas read_csv Keep Column Order

查看:750
本文介绍了Python Pandas read_csv保持列顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CSV文件读入熊猫:

I am reading a CSV file into pandas:

df = pd.read_csv('file.csv')

但是,我注意到没有保留列顺序.我在文档中找不到任何说明来解释在读取CSV文件时如何保持列顺序的东西.

However, I notice that column order is not preserved. I can't find anything in the docs that explain how to keep the column order when reading in the CSV file.

推荐答案

read.csv将表格数据转换为DataFrame对象.由于DataFramekwargs词典,因此不能坚持使用顺序.

read.csv convert tabular data into DataFrame object. Since DataFrame are kwargs dictionary, order is not persevered.

来自 DataFrame read.csv

这篇关于Python Pandas read_csv保持列顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆