-- coding: utf-8 --
“”"
Created on Mon Oct 21 11:22:13 2019
功能:测试读取中文txt文件名,含中文字符串内容
@author: Acer201209
“”"
import pandas as pd
# 文件路径为中文处理
path1 ='D:\\XXXXXXXXXX_加速度.txt'
path2 = 'XXXXXXXXXX_加速度.txt'
path3 = '1.txt'
f = open(path1)
df = pd.read_csv(f)
f.close()
print(df.shape)
#-----txt中存在’非数字’处理,类型为str----------------
#---------path3:文件名为英文处理---------------------------
test1 = pd.read_csv(path3,header = None,sep=' ')
boola = np.where(test1 == '非数字')
boolaa = boola[1] #非数字所在的位置
test11 = test1.copy()
test11[boolaa] = 0
print(test11[5][0])
print(test11[6][0])
print(test11[7][0])
print(test11[8][0])
test111 = test11.values.ravel()
#f.close()
#----------文件名为中文,内容含‘非数字’-----------------------
#---------path2:文件名为中文,内含'非数字'---------------------------
test_china = open(path2,"rt", encoding="utf-8")
test1 = pd.read_csv(test_china,header = None,sep=' ')#
boola = np.where(test1 == '非数字')
boolaa = boola[1] #非数字所在的位置
test11 = test1.copy()
test11[boolaa] = 0
print(test11[5][0])
print(test11[6][0])
print(test11[7][0])
print(test11[8][0])
wave = test11.values.ravel()
test_china.close()
‘’’
f = open(path1)
df = pd.read_csv(f)
f.close()
print(df.shape)
‘’’