Python Pandas: print the csv data in oder with columns

有些话、适合烂在心里 提交于 2020-01-24 20:28:27

问题


 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!


回答1:


You can check unicode-formatting and set:

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

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


来源:https://stackoverflow.com/questions/37136649/python-pandas-print-the-csv-data-in-oder-with-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!