使用Pandas将同一数据框中的两列合并为一列

时间:2019-08-08 17:03:46

标签: python excel pandas pandas-groupby openpyxl

我想在现有列中合并两列,每列都有一个值,具体取决于条件或引用

我尝试使用此功能:

your_prop

现有列为“到达价格”,将填充“到达价格”信息的列为“最后中间价”和“到达价格(本地)”

wb['Arrival Price'] = wb['Arrival Price Price (local)'].map(str)+wb['Last Mid'].map(str)

输出为:

import os, openpyxl, glob, os.path
import pandas as pd
import numpy as np
import math

os.chdir(r'C:\Users\maria.huerfano\Documents\Python_Exercises\join_excel')
wb = pd.read_excel('Markit_EQ_FI_07242019_WEEKLY.xlsx',sheet_name='Sheet1', dtype=str)
eq = pd.read_excel('PRIIPS_EQ_LITE_20190325_20190719.xlsx',sheet_name='Sheet1', dtype=str)
fi = pd.read_excel('CSV_Output_Default_20190325_20190719.xlsx',sheet_name='Sheet1',dtype=str)

wb.insert(17, 'Arrival Price Price (local)', wb['SSB Internal Trade ID'].map(eq.set_index(['SSB Internal Trade ID'])['Arrival Price Price (local)'])) # the condition here is 'SSB Internal Trade ID'

wb.insert(18, 'Last Mid', wb['SSB Internal Trade ID'].map(fi.set_index(['OrderID'])['Last Mid']))# the condition here is 'OrderID' the meaning is the same as 'SSB Internal Trade ID'


wb['Arrival Price'] = wb['Arrival Price Price (local)'].map(str)+wb['Last Mid'].map(str)

0 个答案:

没有答案