How to Create an 8 by 8 Dataframe in Python
To create an 8 by 8 dataframe in Python, you can use the DataFrame() function from the pandas library and the arange() function from the numpy library.
The following example shows how to create an 8 by 8 dataframe in Python using the pandas and numpy libraries.
Using DataFrame() & arange() Function
We can use the DataFrame() and arange() functions to create an 8 by 8 dataframe.
Let’s see how to create a dataframe in Python:
# Import libraries
import pandas as pd
import numpy as np
# Create dataframe
df = pd.DataFrame(np.arange(64).reshape(8, 8))
# Show dataframe
print(df)
Output: 👇️
0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 8 9 10 11 12 13 14 15
2 16 17 18 19 20 21 22 23
3 24 25 26 27 28 29 30 31
4 32 33 34 35 36 37 38 39
5 40 41 42 43 44 45 46 47
6 48 49 50 51 52 53 54 55
7 56 57 58 59 60 61 62 63
In this example, we use the arange() function to create a range of values from 0 to 63 and then reshape it into an 8 by 8 array.
We then use the DataFrame() function to create a dataframe df from this array.
The output shows the 8 by 8 dataframe created using the pandas and numpy libraries.
Conclusion
We can use the DataFrame() function from the pandas library and the arange() function from the numpy library to create an 8 by 8 dataframe in Python.