Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- import pandas
- numpy.random.seed(0)
- index1 = pandas.MultiIndex.from_product(
- [['A'], ['b'], ['one', 'two']],
- names=['City', 'Street', 'House']
- )
- index2 = pandas.MultiIndex.from_product(
- [['C'], ['three', 'four'], ['d']],
- names=['City', 'House', 'Street']
- )
- df1 = pandas.DataFrame(
- [['one-c1', 'one-c2'], ['two-c1', 'two-c2']],
- index=index1,
- columns=['c1', 'c2']
- )
- print(df1)
- df2 = pandas.DataFrame(
- [['three-c2', 'three-c1'], ['four-c2', 'four-c1']],
- index=index2,
- columns=['c2', 'c1']
- )
- print(df2)
- print(pandas.concat([df1, df2]))
- ### the work-around
- index_names = df1.index.names
- df12 = pandas.concat([df1.reset_index(), df2.reset_index()]).set_index(index_names)
Add Comment
Please, Sign In to add comment