|
11 | 11 |
|
12 | 12 | from pandas.errors import ParserError
|
13 | 13 |
|
14 |
| -from pandas import DataFrame, Index, MultiIndex |
| 14 | +from pandas import DataFrame, Index, MultiIndex, read_csv |
15 | 15 | import pandas.util.testing as tm
|
16 | 16 |
|
17 | 17 |
|
@@ -540,3 +540,32 @@ def test_multi_index_unnamed(all_parsers, index_col, columns):
|
540 | 540 | columns = MultiIndex.from_tuples(zip(exp_columns, ["0", "1"]))
|
541 | 541 | expected = DataFrame([[2, 3], [4, 5]], columns=columns)
|
542 | 542 | tm.assert_frame_equal(result, expected)
|
| 543 | + |
| 544 | + |
| 545 | +def test_read_csv_multiindex_columns(): |
| 546 | + # GH#6051 |
| 547 | + s1 = "Male, Male, Male, Female, Female\nR, R, L, R, R\n.86, .67, .88, .78, .81" |
| 548 | + s2 = ( |
| 549 | + "Male, Male, Male, Female, Female\n" |
| 550 | + "R, R, L, R, R\n" |
| 551 | + ".86, .67, .88, .78, .81\n" |
| 552 | + ".86, .67, .88, .78, .82" |
| 553 | + ) |
| 554 | + |
| 555 | + mi = MultiIndex.from_tuples( |
| 556 | + [ |
| 557 | + ("Male", "R"), |
| 558 | + (" Male", " R"), |
| 559 | + (" Male", " L"), |
| 560 | + (" Female", " R"), |
| 561 | + (" Female", " R.1"), |
| 562 | + ] |
| 563 | + ) |
| 564 | + expected = DataFrame( |
| 565 | + [[0.86, 0.67, 0.88, 0.78, 0.81], [0.86, 0.67, 0.88, 0.78, 0.82]], columns=mi |
| 566 | + ) |
| 567 | + |
| 568 | + df1 = read_csv(StringIO(s1), header=[0, 1]) |
| 569 | + tm.assert_frame_equal(df1, expected.iloc[:1]) |
| 570 | + df2 = read_csv(StringIO(s2), header=[0, 1]) |
| 571 | + tm.assert_frame_equal(df2, expected) |
0 commit comments