,可以通过以下步骤实现:
import pandas as pd
# 创建空的DataFrame
df = pd.DataFrame()
# 添加第一个列,大小为n
n = 5
column1 = [i for i in range(n)]
df['Column1'] = column1
# 添加第二个列,大小为m
m = 3
column2 = [i for i in range(m)]
df['Column2'] = column2
pd.DataFrame()
函数创建一个空的DataFrame。df['Column1'] = column1
语句将名为"Column1"的列添加到DataFrame中,并将列表column1
的值赋给该列。df['Column2'] = column2
语句将名为"Column2"的列添加到DataFrame中,并将列表column2
的值赋给该列。领取专属 10元无门槛券
手把手带您无忧上云