運(yùn)行環(huán)境
Python 2.7
操作實(shí)例
1.原始文本格式:空格分隔的txt,例如
1
2
3
4
|
2016-03-22 00:06:24.4463094 中文測(cè)試字符 2016-03-22 00:06:32.4565680 需要編輯encoding 2016-03-22 00:06:32.6835965 abc 2016-03-22 00:06:32.8041945 egb |
2.pandas 讀取數(shù)據(jù)
1
2
3
4
5
6
|
import pandas as pd data = pd.read_table('Z:/test.txt',header=None,encoding='gb2312',delim_whitespace=True,index_col=0) #header=None:沒(méi)有每列的column name,可以自己設(shè)定 #encoding='gb2312':其他編碼中文顯示錯(cuò)誤 #delim_whitespace=True:用空格來(lái)分隔每行的數(shù)據(jù) #index_col=0:設(shè)置第1列數(shù)據(jù)作為index |
以上這篇python Pandas 讀取txt表格的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/u011077672/article/details/50960580