【单列 拆成多列】

# -*- coding: utf-8 -*-
"""
Created on Mon Sep 19 09:06:34 2022

@author: Lenovo
"""

import os
import numpy as np
import pandas as pd

path=r'D:\Fluxnet\666'
# pathout=r'D:\Fluxnet\666\jieguo'
for sole in os.listdir(path):
    
    a=pd.read_csv(os.path.join(path,sole))
  
    a['SW_IN_F_MDS']=np.nan
    a['NETRAD']=np.nan
    a['G_F_MDS']=np.nan
    a['TA_F_MDS']=np.nan
    a['RH']=np.nan
    a['WD']=np.nan 
    a['WS']=np.nan 
    
    a['PA_F']=np.nan
    a['VPD_F_MDS']=np.nan
    a['NDVI']=np.nan
    a['TS_F_MDS_1']=np.nan
    a['SWC_F_MDS_1']=np.nan
    a['TA_F_MDS']=np.nan
    
    a['Drivers'].replace(np.nan,-9999,inplace=True)

    
    b=a.loc[a['Drivers']!=-9999]
    print(b)
    
    for i in b.columns[6:]:
        
        # print(i)
        
        c=b[b['Drivers'].str.contains(i)]

        c[i].replace(np.nan,'+',inplace=True)
        print(c)

        
        a[i]=c[i]
        
    b=a.count(axis=1)-6
    b=pd.DataFrame(b)
    
    a['n_drivers']=b
    a['n_drivers'].replace([-1,-2,-3],np.nan,inplace=True)
    
    a['Drivers'].replace(-9999,np.nan,inplace=True)



    a.to_csv(os.path.join(path,sole+'.csv'),index = False)


    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值