python提取一列数据
方法一:
import pandas as pd
import numpy as np
result = []
for name in ["./IQXFactoryEfficiency20210125.csv", "./IQXFactoryEfficiency20210126.csv",
"./IQXFactoryEfficiency20210127.csv", "./IQXFactoryEfficiency20210205.csv",
"./IQXFactoryEfficiency20210201.csv", "./IQXFactoryEfficiency20210224.csv"] :
df = pd.read_csv(name)
result = np.append(result, df['SerialNum'].to_numpy())
print(result)
pd.DataFrame(np.unique(result)).to_csv('sns2.csv')
二
import os
import pandas as pd
import numpy as np
result = []
for file in os.listdir("D:\\Log"): # 遍历当前目录
if file.endswith(".csv"): # 读取csv文件
df = pd.read_csv(file)
result = np.append(result, df['SerialNum'].to_numpy()) # 追加文件内容
print(result)
unique_data = np.unique(result) # 去重
pd.DataFrame(unique_data).to_csv('C:\\Users\\jxiong\\Desktop\\sns2.csv') #保存
3, 提取两列
import pandas as pd
import numpy as np
result = pd.DataFrame()
for name in ["./IQXFactoryEfficiency20210125.csv", "./IQXFactoryEfficiency20210126.csv",
"./IQXFactoryEfficiency20210127.csv", "./IQXFactoryEfficiency20210205.csv",
"./IQXFactoryEfficiency20210201.csv", "./IQXFactoryEfficiency20210224.csv"] :
df = pd.read_csv(name)
result = pd.concat([result, df[['SerialNum','AssyHWRev']]])
print(result.drop_duplicates())
uniq_df = result.drop_duplicates()
uniq_df.to_csv('sns3.csv')
4, 提取两列
import pandas as pd
import numpy as np
result = pd.DataFrame()
for file in os.listdir("./"): # 遍历当前目录
if file.endswith(".csv"): # 读取csv文件
df = pd.read_csv(file)
result = pd.concat([result, df[['SerialNum','AssyHWRev']]])
print(result.drop_duplicates())
uniq_df = result.drop_duplicates()
uniq_df.to_csv('sns3.csv')