我有2个数据集。
let tabViewController =
storyboard?.instantiateViewController(withIdentifier: "TabController") as? TabController
view.window?.rootViewController = tabViewController
view.window?.makeKeyAndVisible()
输出:
dict1 =pd.DataFrame({'Name' : ['A','B','C','D'], 'Score' : [19,20,11,12]})
list1 =pd.DataFrame(['Math', 'English', 'History', 'Science'])
concat_data = pd.concat([dict1,list1])
我正在寻找的输出:
Name Score 0
0 A 19.0 NaN
1 B 20.0 NaN
2 C 11.0 NaN
3 D 12.0 NaN
0 NaN NaN Math
1 NaN NaN English
2 NaN NaN History
3 NaN NaN Science
有人可以帮我吗?
答案 0 :(得分:1)
您需要做的就是传递正确的class SudokuAlgorithm
{
public string[,] sudokuFields;
public string[,] sudokuUnsolved;
public bool corectRow;
public bool correctColumn;
public bool correctField;
private static int UNASSIGNED = 0;
public SudokuAlgorithm()
{
sudokuFields = new string[9, 9];
}
public SudokuAlgorithm(string[,] sudoku, int indexRow, int indexColumn)
{
this.sudokuFields = sudoku;
sudokuUnsolved = sudoku;
correctRow = TestRow(indexRow, indexColumn);
correctColumn = TestColumn(indexRow, indexColumn);
correctField = TestArea(indexRow, indexColumn);
SolveSudoku();
}
private void SolveSudoku()
{
for(int i=0;i<9;i++) //Column
{
for(int j=0;j<9;j++) // Row
{
if(SudokuFieldFree(j,i) == true)
{
for(int k=1;k<=9;k++)
{
sudokuFields[i, j] = k.ToString();
if(TestRow(j,i) == false || TestColumn(j,i) == false || TestArea(j,i) == false)
{
sudokuField[i, j] = "";
}
else
{
break;
}
}
if (sudokuFields[i, j] == "")
{
if(j!=0)
{
for(int l =j-1;l>=0;l--)
{
if (SudokuAreaFreeUnsolved(l, i) == true)
{
j = l-1;
sudokuFields[i, l] = "";
break;
}
}
}
else
{
i = i - 1;
j = 8;
}
}
}
}
}
}
private bool SudokuAreaFree(int indexRow, int indexColumn)
{
bool free= false;
if (sudokuFields[indexColumn, indexRow] == "" || sudokuFields[indexColumn, indexRow] == " " || sudokuFields[indexColumn, indexRow] == null)
{
free = true;
return free;
}
return free;
}
private bool SudokuAreaFreeUnsolved(int indexRow, int indexColumn)
{
bool frei = false;
if (sudokuUnsolved[indexColumn, indexRow] == "" || sudokuUnsolved[indexColumn, indexRow] == " " || sudokuUnsolved[indexColumn, indexRow] == null)
{
free= true;
return free;
}
return free;
}
private bool TestRow(int indexRow, int indexColumn)
{
bool valid = true;
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (sudokuFields[i, indexRow] == sudokuFields[j, indexRow] && sudokuFields[i, indexRow] != " " && i != j)
{
valid = false;
return valid;
}
}
}
return valid;
}
private bool TestColumn(int indexRow, int indexColumn)
{
bool valid = true;
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (sudokuFields[indexColumn, i] == sudokuFields[indexColumn, j] && sudokuFields[indexColumn, i] != " " && i!=j)
{
valid = false;
return valid;
}
}
}
return valid;
}
private bool TestArea(int indexRow, int indexColumn)
{
bool valid = true;
if (indexColumn >= 0 && indexColumn <= 2 && indexRow >= 0 && indexRow <= 2)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 3 && indexColumn <= 5 && indexRow >= 0 && indexRow <= 2)
{
for (int i = 3; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 6 && indexColumn <= 8 && indexRow >= 0 && indexRow <= 2)
{
for (int i = 6; i < 9; i++)
{
for (int j = 0; j < 3; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 0 && indexColumn <= 2 && indexRow >= 3 && indexRow <= 5)
{
for (int i = 0; i < 3; i++)
{
for (int j = 3; j < 6; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 3 && indexColumn <= 5 && indexRow >= 3 && indexRow <= 5)
{
for (int i = 3; i < 6; i++)
{
for (int j = 3; j < 6; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 6 && indexColumn <= 8 && indexRow >= 3 && indexRow <= 5)
{
for (int i = 6; i < 9; i++)
{
for (int j = 3; j < 6; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 0 && indexColumn <= 2 && indexRow >= 6 && indexRow <= 8)
{
for (int i = 0; i < 3; i++)
{
for (int j = 6; j < 9; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 3 && indexColumn <= 5 && indexRow >= 6 && indexRow <= 8)
{
for (int i = 3; i < 6; i++)
{
for (int j = 6; j < 9; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
else if (indexColumn >= 6 && indexColumn <= 8 && indexRow >= 6 && indexRow <= 8)
{
for (int i = 3; i < 6; i++)
{
for (int j = 6; j < 9; j++)
{
if (sudokuFields[indexColumn, indexRow] == sudokuFields[i, j] && sudokuFields[indexColumn, indexRow] != " " && indexColumn != i && indexRow != j)
{
valid = false;
return valid;
}
}
}
}
return valid;
}
}
。 default behavior for concat是axis
,这意味着操作需要按索引或行进行,而您则需要按列进行操作:
轴:{0 /“索引”,1 /“列”},默认为0 要沿着的轴。
axis=0
输出:
concat_data = pd.concat([dict1,list1],axis=1)
print(concat_data)