dataframe from two series

In [1]: s1 = pd.Series([1, 2], index=['A', 'B'], name='s1')

In [2]: s2 = pd.Series([3, 4], index=['A', 'B'], name='s2')

In [3]: pd.concat([s1, s2], axis=1)
Out[3]:
   s1  s2
A   1   3
B   2   4

In [4]: pd.concat([s1, s2], axis=1).reset_index()
Out[4]:
  index  s1  s2
0     A   1   3
1     B   2   4

Here is what the above code is Doing:
1. Create two Series objects, s1 and s2, with the same index.
2. Use pd.concat() to concatenate them along the columns axis.
3. Use reset_index() to create a new index for the DataFrame.

The output of the code is a DataFrame with two columns, s1 and s2, and a new index.

You can also use pd.concat() to concatenate along the rows axis. To do this, set the axis parameter to 0:

In [5]: pd.concat([s1, s2], axis=0)
Out[5]:
A 1
B 2
A 3
B 4
dtype: int64

The output of the code is a Series with a new index.

You can also specify the keys parameter to label the different pieces of the concatenated object:

In [6]: pd.concat([s1, s2], keys=[‘s1’, ‘s2’])
Out[6]:
s1 A 1
B 2
s2 A 3
B 4
dtype: int64

The output of the code is a Series with a MultiIndex.

You can also specify the keys parameter when concatenating along the columns axis. In this case, the keys become the column names:

In [7]: pd.concat([s1, s2], keys=[‘s1’, ‘s2′], axis=1)
Out[7]:
s1 s2
A 1 3
B 2 4

The output of the code is a DataFrame with a MultiIndex for the columns.

You can also specify the join parameter to control how the indexes are handled. By default, pd.concat() joins the indexes of the input objects on the intersection of the indexes (inner join):

In [8]: pd.concat([s1, s2])
Out[8]:
A 1
B 2
A 3
B 4
dtype: int64

In [9]: pd.concat([s1, s2], join=’inner’)
Out[9]:
A 1