更改熊猫字典的键值

时间:2019-08-08 23:18:16

标签: python pandas dictionary

我想根据用户的输入来制作字典。但是当我尝试从名为“ key_columns”的列表中添加列名称时,Python说:不能将orient ='columns'的columns参数使用

我尝试使用orient = index,但是对“ list”对象的错误更改没有属性“ values”。

keys_words = list()
keys_columns = list()
while True:
    line_columns = input('Enter the columns name:').rstrip().title().replace(' ', '_')
    if line_columns == 'done' or line_columns == 'Done':
        break
    keys_columns.append(line_columns)
    line_words = input('Enter the words: ').rstrip().lower()
    keys_words.append(line_words)
words_list = [i.split(', ') for i in keys_words]

import pandas as pd
dictionary = pd.DataFrame.from_dict(words_list, columns = keys_columns)

我希望keys_columns中的值代替默认值(零,一个,等等)。 如果我运行...。dictionary.columns = keys_columns有效 但是为什么呢?

0 个答案:

没有答案
相关问题