Pandas create empty DataFrame with only column names

后端 未结 4 1775
情歌与酒
情歌与酒 2021-01-29 18:38

I have a dynamic DataFrame which works fine, but when there are no data to be added into the DataFrame I get an error. And therefore I need a solution to create an empty DataFra

4条回答
  •  旧时难觅i
    2021-01-29 19:09

    Are you looking for something like this?

        COLUMN_NAMES=['A','B','C','D','E','F','G']
        df = pd.DataFrame(columns=COLUMN_NAMES)
        df.columns
    
       Index(['A', 'B', 'C', 'D', 'E', 'F', 'G'], dtype='object')
    

提交回复
热议问题