######txt文件转换成csv文件

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# 1.以csv方式打开txt文件
dg =pd.read_csv('C:\\Users\\86178\\PycharmProjects\\pythonProject\\ethylene_methane.txt', delim_whitespace=True, skiprows=[0], header=None)
# 2.添加表头
dg = dg.rename(columns = {0:'Time (seconds)', 1:'Methane conc (ppm)', 2:'Ethylene conc (ppm)',3:'Sensor1',4:'Sensor2',5:'Sensor3',6:'Sensor4',7:'Sensor5',8:'Sensor6',9:'Sensor7',10:'Sensor8',11:'Sensor9',12:'Sensor10',13:'Sensor11',14:'Sensor12',15:'Sensor13',16:'Sensor14',17:'Sensor15',18:'Sensor16'})
# 3.保存csv文件
dg.to_csv('ethylene_methane.csv')
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐