Python 熊猫:每个列的故障设置值

Python 熊猫:每个列的故障设置值,python,pandas,Python,Pandas,我有一个空的Pandas数据框,我正在尝试向其中添加一行。我的意思是: text_img_count = len(BeautifulSoup(html, "lxml").find_all('img')) print 'img count: ', text_img_count keys = ['text_img_count', 'text_vid_count', 'text_link_count', 'text_par_count', 'text_h1_count',

我有一个空的Pandas数据框,我正在尝试向其中添加一行。我的意思是:

text_img_count = len(BeautifulSoup(html, "lxml").find_all('img'))
    print 'img count: ', text_img_count

keys = ['text_img_count', 'text_vid_count', 'text_link_count', 'text_par_count', 'text_h1_count',
              'text_h2_count', 'text_h3_count', 'text_h4_count', 'text_h5_count', 'text_h6_count',
                       'text_bold_count', 'text_italic_count', 'text_table_count', 'text_word_length', 'text_char_length',
                       'text_capitals_count', 'text_sentences_count', 'text_middles_count', 'text_rows_count',
                       'text_nb_digits', 'title_char_length', 'title_word_length', 'title_nb_digits']
    values = [text_img_count, text_vid_count, text_link_count, text_par_count, text_h1_count,
                                   text_h2_count, text_h3_count, text_h4_count, text_h5_count, text_h6_count,
                                   text_bold_count, text_italic_count, text_table_count, text_word_length,
                                   text_char_length, text_capitals_count, text_sentences_count, text_middles_count,
                                   text_rows_count, text_nb_digits, title_char_length, title_word_length, title_nb_digits]

    numeric_df = pd.DataFrame()
    for key, value in zip(keys, values):
        numeric_df[key] = value

    print numeric_df.head()
然而,结果是:

img count:  2
Empty DataFrame
Columns: [text_img_count, text_vid_count, text_link_count, text_par_count, text_h1_count, text_h2_count, text_h3_count, text_h4_count, text_h5_count, text_h6_count, text_bold_count, text_italic_count, text_table_count, text_word_length, text_char_length, text_capitals_count, text_sentences_count, text_middles_count, text_rows_count, text_nb_digits, title_char_length, title_word_length, title_nb_digits]
Index: []

[0 rows x 23 columns]
这使得在我为每个列分配了值之后,
numeric_df
似乎是空的

发生什么事了


谢谢你的帮助

我通常在空数据框中添加一列,就是将信息附加到列表中,然后给它一个数据框结构。例如:

df=pd.DataFrame()
L=['a','b']

df['SomeName']=pd.DataFrame(L)
如果列表由数字组成,则必须使用pd.Series()