0
0
Data Analysis Pythondata~5 mins

DataFrame structure (index, columns, values) in Data Analysis Python

Choose your learning style9 modes available
Introduction

A DataFrame is like a table that helps you organize data in rows and columns. Knowing its structure helps you find and use data easily.

When you want to see how your data is arranged before analyzing it.
When you need to select specific rows or columns for your work.
When you want to check the labels of rows and columns to avoid mistakes.
When you want to understand the shape and size of your data.
When you want to extract just the values without the labels for calculations.
Syntax
Data Analysis Python
df.index
# Shows row labels

df.columns
# Shows column labels

df.values
# Shows data values as an array

df.index gives you the row names or numbers.

df.columns gives you the column names.

Examples
This shows the row labels, which by default are numbers starting at 0.
Data Analysis Python
import pandas as pd

data = {'Name': ['Anna', 'Bob'], 'Age': [28, 34]}
df = pd.DataFrame(data)

print(df.index)
This shows the column names: 'Name' and 'Age'.
Data Analysis Python
print(df.columns)
This shows the actual data inside the table as a list of lists.
Data Analysis Python
print(df.values)
Sample Program

This program creates a simple table of cities and their populations, then prints the row labels, column names, and the data values.

Data Analysis Python
import pandas as pd

data = {'City': ['Paris', 'London', 'Berlin'], 'Population': [2148000, 8982000, 3769000]}
df = pd.DataFrame(data)

print('Index:', df.index)
print('Columns:', df.columns)
print('Values:', df.values)
OutputSuccess
Important Notes

The index helps you identify rows uniquely.

The columns help you identify what each column means.

The values give you the raw data without labels.

Summary

A DataFrame has three main parts: index (rows), columns, and values (data).

Use df.index to see row labels, df.columns for column names, and df.values for the data.

Understanding these helps you work with data clearly and avoid mistakes.