简体   繁体   中英

merge two different excels based on two conditions

I have two excels. The first one is the dependent variable: data with Date & station ID , With date as the 'index' of dataframe, and station ID for headers. as shown as below, 在此处输入图像描述 The second one (independent variable) is the data I used to simulate the dependent variable(first excel above), also with Date , have the format as one column for year and the other two for month and date respectively. As shown in the image below自变量图像

what I want is 1. skip the NaN value in the first excel. 2. add the value in the first table to the second excel based on the same date and the same water monitoring station ID These are the codes I write until now, I am new to python and have been struggling for days.

import csv
import pandas
import pandas as pd
import openpyxl
from numpy import size
from pandas import DataFrame
from datetime import datetime
import datetime as dt
import numpy as np
# firstly, exclude those don't have value
# read csv file(2)
csvB4reflectance = pd.read_csv('GEEdownload.csv')
b4 = pd.read_csv('GEEdownload.csv',sep=',',parse_dates=['system:time_start'])
b4.set_index('system:time_start',inplace=True) #set index and change index type, to drop out
print(csvB4reflectance)
path = 'F:/72hourtimewindow/project/waterqualitydate/29UMT/'
excelorder = pd.read_excel(path+'Stationwithorder.xls',header = 0, index_col=0)
print(excelorder)
b41 = b4.dropna(axis=0,how='all')
print(b41)
# process this table, start to calculate when data in the form is not NaN
b41num = b41.to_numpy()
print(b41num)
# import excel order
for i in b41num:
    for j in i:
        if j == NaN:
            break
        else:
            if 
     print(j)```

I have came across this problem, the second chart need to be melted firstly!~ and then everything seems to be esay

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM