Я предположил, что ваши данные еще не верны, поскольку ваш ожидаемый результат возможен, но не по вашей логике прямо сейчас.
Вы упускаете третий key column
в second_df
, который является capacity
. Если мы добавим этот столбец и выполним left merge
, мы сможем достичь ожидаемого результата.
Кстати, нам не нужно указывать столбцы в качестве индекса, поэтому решение выглядит следующим образом.
# Clean up and create correct dataframes
first_df=pd.DataFrame([['2001','Abu Dhabi','100-','462'],
['2001','Abu Dhabi','100','44'],
['2001','Abu Dhabi','200','657'],
['2001','Dubai','100-','40'],
['2001','Dubai','100','30'],
['2001','Dubai','200','51'],
['2002','Abu Dhabi','100-','300'],
['2002','Abu Dhabi','100','220'],
['2002','Abu Dhabi','200','56'],
['2002','Dubai','100-','55'],
['2002','Dubai','100','67'],
['2002','Dubai','200','89']],columns=['Year','Emirate','Capacity','Number'])
second_df=pd.DataFrame([['2001','Abu Dhabi','100-','Performed','45'],
['2001','Abu Dhabi','100','Not Performed','76'],
['2001','Abu Dhabi','','',''],
['2001','Dubai','100-','Performed','90'],
['2001','Dubai','100','Not Performed','50'],
['2001','Dubai','','',''],
['2002','Abu Dhabi','100-','Performed','78'],
['2002','Abu Dhabi','100','Not Performed','45'],
['2002','Abu Dhabi','', '', ''],
['2002','Dubai','100-','Performed','76'],
['2002','Dubai','100','Not Performed','58'],
['2002','Dubai', '', '', '']],columns=['Year','Emirate','Capacity','Type','Value'])
# Perform a left merge to get correct output
merged=first_df.merge(second_df,how='left',on=['Year', 'Emirate', 'Capacity'])
Выход
Year Emirate Capacity Number Type Value
0 2001 Abu Dhabi 100- 462 Performed 45
1 2001 Abu Dhabi 100 44 Not Performed 76
2 2001 Abu Dhabi 200 657 NaN NaN
3 2001 Dubai 100- 40 Performed 90
4 2001 Dubai 100 30 Not Performed 50
5 2001 Dubai 200 51 NaN NaN
6 2002 Abu Dhabi 100- 300 Performed 78
7 2002 Abu Dhabi 100 220 Not Performed 45
8 2002 Abu Dhabi 200 56 NaN NaN
9 2002 Dubai 100- 55 Performed 76
10 2002 Dubai 100 67 Not Performed 58
11 2002 Dubai 200 89 NaN NaN
:) Compile in VS2008 and remember to check out the Bin{Debug|Release} folder of the project location to see the exe
If you're in visual studio, hit F7.
The application will be compiled into an exe file that can then be executed. It will usually be located underneath your solution directory:
SolutionDir\Bin\(Debug|Release)\Solution.exe
This file will only be able to run on Windows computers that have the necessary version of the CLR installed. As far as I know there's no way around that requirement.
Build it in Visual Studio. It should run on any Windows system that has the correct framework installed. (Potentially .NET 3.5sp1, depending on what you included.)
WPF по умолчанию является .exe, но для него требуется .NET 3+. Вы не можете создать WPF .exe и ожидать, что он будет работать на всех версиях Windows, независимо от того, установлена ли платформа, для которой вы скомпилировали ваше приложение.
Это похоже на библиотечную зависимость в C / C ++. Некоторые библиотеки не работают в старых версиях Windows.