Q:

Write a Pandas program to stack two given series vertically and horizontally

0

Write a Pandas program to stack two given series vertically and horizontally.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
series1 = pd.Series(range(10))
series2 = pd.Series(list('pqrstuvwxy'))
print("Original Series:")
print(series1)
print(series2)
series1.append(series2)
df = pd.concat([series1, series2], axis=1)
print("\nStack two given series vertically and horizontally:")
print(df)

Sample Output:

Original Series:
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: int64
0    p
1    q
2    r
3    s
4    t
5    u
6    v
7    w
8    x
9    y
dtype: object

Stack two given series vertically and horizontally:
   0  1
0  0  p
1  1  q
2  2  r
3  3  s
4  4  t
5  5  u
6  6  v
7  7  w
8  8  x
9  9  y

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now