📜  python pandas shape - Python (1)

📅  最后修改于: 2023-12-03 15:04:07.109000             🧑  作者: Mango

Python Pandas Shape

Pandas is a popular data analysis library for Python. One of the key features of Pandas is the ability to manipulate and reshape data.

The shape attribute of a Pandas DataFrame gives you the dimensions of the data, represented as a tuple of (rows, columns).

Here is an example:

import pandas as pd

# create a DataFrame with 3 rows and 4 columns
data = {
    'name': ['Alice', 'Bob', 'Charlie'],
    'age': [25, 30, 35],
    'score': [80, 90, 85],
    'gender': ['F', 'M', 'M']
}
df = pd.DataFrame(data)

print(df.shape)  # (3, 4)

In this example, the df DataFrame has 3 rows and 4 columns.

You can use the shape attribute to check the dimensions of your data before and after data manipulations to ensure that the data has the expected shape.

Conclusion

The shape attribute of a Pandas DataFrame is a useful tool for checking the dimensions of your data. Use it to ensure that your data has the expected shape before and after data manipulations.