简体   繁体   English

在 dask 中将 csv 导入数据框时命名列

[英]Name columns when importing csv to dataframe in dask

I would like to name columns when I import a csv to a dataframe with dask in Python.The code I use looks like this:当我在 Python 中使用 dask 将 csv 导入到数据框时,我想命名列。我使用的代码如下所示:

 for i in range(1, files + 1): filename = str(i) + 'GlobalActorsHeatMap.csv' runs[i] = dd.read_csv(filename, header=None)

I would like to use an array with names for each column:我想为每列使用一个带有名称的数组:

names = ['tribute', 'percent_countries_active', 'num_wars', 'num_tributes', 'war', 'war_to_tribute_ratio', 'US_wealth', 'UK_wealth', 'NZ_wealth' ]名称 = ['tribute'、'percent_countries_active'、'num_wars'、'num_tributes'、'war'、'war_to_tribute_ratio'、'US_wealth'、'UK_wealth'、'NZ_wealth']

Is this possible to do directly?这可以直接做吗?

Just use the names argument for the read_csv只需使用read_csvnames参数

names = [...]
dd.read_csv(filename, header=None, names=names)

Read more here 在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM