I have this following data frame, I'm constructing a Python function(to use it in Labview) that basically only does: data pair & data cleaning.
数据框架是这样的。
我需要pandas单独挑出每一列(除了'Date'),并与
'Date'
(自定义索引)配对,然后再分别写入单个CSV文件中。我需要确保压力列的数据不包含任何
'0'
的数字,而对于每个温度列,等于
0 or bigger than 150
的数据将被过滤掉。
下面是我的Python函数,参数
x1 and x2
将通过LabVIEW输入,指定一个用户选择的 "日期范围"。
def data_slice(x1, x2):
import pandas as pd
df = pd.read_csv('exp_log.csv')
df.set_index('Date', inplace=True)
df_p = df.loc[x1:x2, 'Pressure']
filt = (df_p['Pressure'] == 0)
df_p = df_p.loc[~filt]
df_p.to_csv('modified_pressure.csv', index=True)
all_cols = list(df.columns)
temp_cols = all_cols[1:]
for i in temp_cols:
df_i = df.loc[x1:x2, 'i']
filt = (df_i > 150) | (df_i == 0)
df_i = df_i.loc[~filt]
df_i.to_csv(f'modified_temp{i}.csv', index=True)
我的问题是:....,这段Python代码是否真的能正常工作?也就是说,是否能有效地写出单个CSV文件?鉴于实际的exp_log.csv文件是一个超级大的文件,包含了几天的数据记录....