1
我想創建具有可變列數的熊貓數據幀。Python熊貓創建具有可變數量輸入的數據幀
import pandas as pd
import numpy as np
MonthNumber = np.array([1,1,2,4,5,6,5])
Type1 = np.array(['A','B','C',A','A','B','C'])
Type2 = np.array([1,1,0,1,0,0,1])
Data = np.array([1.1,3,.52,34,15,45,34])
Data2 = Data * 1.1
Data3 = Data * 2
def variableDataFrame(*args):
df = pd.DataFrame({'MonthNumber':args1, 'Data':args2})
print df.columns
所以,函數調用看起來像:
variableDataFrame(MonthNumber,Data) #prints MonthNumber,Data
variableDataFrame(MonthNumber,Type1,Data) # prints MonthNumber,Type1,Data