熊猫无法识别一列

时间:2020-11-12 19:17:24

标签: python-3.x pandas

我有一个csv,其中包含从twint抓取的推文。

enter image description here

现在,当尝试列出或删除列或基本上进行任何其他操作时,它并不仅仅标识“ id”列。

如果我尝试这样做,

def clean_file_and_save(filename):

    main = pd.read_csv('./data/' + filename, index_col=0)
    main_copy = main.copy()
    
    print(main_copy.columns)

Output: Index(['conversation_id', 'created_at', 'date', 'time', 'timezone', 'user_id',
       'username', 'name', 'place', 'tweet', 'language', 'mentions', 'urls',
       'photos', 'replies_count', 'retweets_count', 'likes_count', 'hashtags',
       'cashtags', 'link', 'retweet', 'quote_url', 'video', 'thumbnail',
       'reply_to'],

它仅显示从conversation_id开始的所有列。

在尝试删除它时:

main_copy.drop(columns=['id',... , 'name'], inplace=True)

Error: KeyError: "['id'] not found in axis"

知道为什么会这样吗?

0 个答案:

没有答案