如何使用符号而不是字符串来寻址 DataFrame 中的 Daru Vectors?
How do I address Daru Vectors in a DataFrame using symbols rather than strings?
我在很多在线代码示例中都看到了这种情况,但是当我解析我的 CSV 文件时,我得到的只是作为列索引的字符串,比如
> data = Daru::DataFrame.from_csv('my_fancy_data.csv')
> data[:user_id]
IndexError: Specified index :user_id does not exist
> data['user_id']
=> #<Daru::Vector(42815)>
user_id
0 z0udgxc0lusu1gr4xj65
1 28080
2 28080
... ...
data = Daru::DataFrame.from_csv('my_fancy_data.csv', headers: true, header_converters: :symbol)
来自文档:
You can specify all the options to the .from_csv
function that you do to the Ruby CSV.read()
function, since this is what is used internally.
我在很多在线代码示例中都看到了这种情况,但是当我解析我的 CSV 文件时,我得到的只是作为列索引的字符串,比如
> data = Daru::DataFrame.from_csv('my_fancy_data.csv')
> data[:user_id]
IndexError: Specified index :user_id does not exist
> data['user_id']
=> #<Daru::Vector(42815)>
user_id
0 z0udgxc0lusu1gr4xj65
1 28080
2 28080
... ...
data = Daru::DataFrame.from_csv('my_fancy_data.csv', headers: true, header_converters: :symbol)
来自文档:
You can specify all the options to the
.from_csv
function that you do to the RubyCSV.read()
function, since this is what is used internally.