Pandas: Creating DataFrame from Series

前端 未结 3 1131
清酒与你
清酒与你 2020-12-29 01:36

My current code is shown below - I\'m importing a MAT file and trying to create a DataFrame from variables within it:

mat = loadmat(file_path)  # load mat-fi         


        
3条回答
  •  悲&欢浪女
    2020-12-29 02:19

    No need to initialize an empty DataFrame (you weren't even doing that, you'd need pd.DataFrame() with the parens).

    Instead, to create a DataFrame where each series is a column,

    1. make a list of Series, series, and
    2. concatenate them horizontally with df = pd.concat(series, axis=1)

    Something like:

    series = [pd.Series(mat[name][:, 1]) for name in Variables]
    df = pd.concat(series, axis=1)
    

提交回复
热议问题