Informatics Practices

Write a program to create a Dataframe that stores two columns, which store the Series objects of the previous two questions (12 and 13).

Python Pandas

1 Like

Answer

import pandas as pd
import numpy as np
data = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
S1 = pd.Series(data)
arr = np.arange(1, 11)
S2 = pd.Series(arr * 5)
df = pd.DataFrame({'Characters': S1, 'Table of 5': S2})

print(df)

Output

  Characters  Table of 5
0          a           5
1          b          10
2          c          15
3          d          20
4          e          25
5          f          30
6          g          35
7        NaN          40
8        NaN          45
9        NaN          50

Answered By

1 Like


Related Questions