Introduction
We specify column names and index to organize data clearly and access it easily, just like labeling folders and files in real life.
pd.DataFrame(data, columns=[list_of_column_names], index=[list_of_index_labels])
import pandas as pd data = [[10, 20], [30, 40]] df = pd.DataFrame(data, columns=['A', 'B'], index=['row1', 'row2']) print(df)
import pandas as pd # Create DataFrame with default index but custom columns data = [[1, 2], [3, 4]] df = pd.DataFrame(data, columns=['X', 'Y']) print(df)
import pandas as pd # Create DataFrame with custom index only data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.DataFrame(data, index=['person1', 'person2']) print(df)
import pandas as pd # Data without headers data = [[100, 200], [300, 400], [500, 600]] # Specify column names and index labels df = pd.DataFrame(data, columns=['Sales', 'Profit'], index=['Jan', 'Feb', 'Mar']) print(df)
import pandas as pd data = [[10, 20], [30, 40]] df = pd.DataFrame(data, columns=['A', 'B'], index=['row1', 'row2']) print(df)
import pandas as pd data = [[1, 2], [3, 4]] df = pd.DataFrame(data, columns='X,Y', index=['r1', 'r2']) print(df)
data = [[1, 2], [3, 4], [5, 6]]
Pass the test and this pattern moves unknown