1.txt文件转换成csv文件
目录0.整体代码1.以csv方式打开txt文件2.给csv添加表头3.保存csv文件0.整体代码import numpy as np # linear algebraimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)dg =pd.read_csv('C:\\Users\\86178\\PycharmProje
·
######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')
更多推荐
已为社区贡献1条内容
所有评论(0)