Python Pandas:在带有列的oder中打印csv数据 [英] Python Pandas: print the csv data in oder with columns

查看:121
本文介绍了Python Pandas:在带有列的oder中打印csv数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,我正在使用pandas读取csv文件数据并进行打印.代码如下所示:

 Hi I am new with python, I am using pandas to read the csv file data, and print it. The code is shown as following:

import numpy as np

import pandas as pd

import codecs

from  pandas import Series, DataFrame

dframe = pd.read_csv("/home/vagrant/geonlp_japan_station.csv",sep=',',    
encoding="Shift-JIS")
print (dframe.head(2))

但是数据打印如下

but the data is printed like as following(I just give example to show it)

但是,我希望数据按如下所示的列排序:

However, I want the data to be order with columns like as following:

谢谢,我不知道如何使打印的数据清晰!

I don't know how to make the printed data be clear, thanks in advance!

推荐答案

您可以检查 unicode-formatting 并设置:

You can check unicode-formatting and set:

pd.set_option('display.unicode.east_asian_width', True)

我使用UTF-8版本 csv :

I test it with UTF-8 version csv:

dframe = pd.read_csv("test/geonlp_japan_station/geonlp_japan_station_20130912_u.csv") 

似乎输出的对齐效果更好.

and it seems align of output is better.

pd.set_option('display.unicode.east_asian_width', True)
print dframe


pd.set_option('display.unicode.east_asian_width', False)
print dframe

这篇关于Python Pandas:在带有列的oder中打印csv数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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