大数据集的数据重塑

时间:2017-10-26 20:13:24

标签: python pandas numpy dataframe reshape

我想重塑我的np数组并将其呈现为DF。我的初始数据集是2930行。我的标题/列包含以下(80)元素:

Order;PID;MS SubClass;MS Zoning;Lot Frontage;Lot Area;Street;Alley;Lot Shape;Land Contour;Utilities;Lot Config;Land Slope;Neighborhood;Condition 1;Condition 2;Bldg Type;House Style;Overall Qual;Overall Cond;Year Built;Year Remod/Add;Roof Style;Roof Matl;Exterior 1st;Exterior 2nd;Mas Vnr Type;Mas Vnr Area;Exter Qual;Exter Cond;Foundation;Bsmt Qual;Bsmt Cond;Bsmt Exposure;BsmtFin Type 1;BsmtFin SF 1;BsmtFin Type 2;BsmtFin SF 2;Bsmt Unf SF;Total Bsmt SF;Heating;Heating QC;Central Air;Electrical;1st Flr SF;2nd Flr SF;Low Qual Fin SF;Gr Liv Area;Bsmt Full Bath;Bsmt Half Bath;Full Bath;Half Bath;Bedroom AbvGr;Kitchen AbvGr;Kitchen Qual;TotRms AbvGrd;Functional;Fireplaces;Fireplace Qu;Garage Type;Garage Yr Blt;Garage Finish;Garage Cars;Garage Area;Garage Qual;Garage Cond;Paved Drive;Wood Deck SF;Open Porch SF;Enclosed Porch;3Ssn Porch;Screen Porch;Pool Area;Pool QC;Fence;Misc Feature;Misc Val;Mo Sold;Yr Sold;Sale Type;Sale Condition;SalePrice

我尝试了以下代码:

df = pd.DataFrame(np.array(results[1:]).reshape(2930,15,-1), columns = results[0])

结果==>

  

ValueError:无法将大小为2930的数组重塑为形状   (2930,15,newaxis)

为什么这不可能?将get数据集导入DataFrame的可能解决方案?谢谢,非常感谢。

1 个答案:

答案 0 :(得分:1)

如果您最初是从文件中读取它,可以使用pd.read_csv(sep =&#39 ;;')来解析每个列...