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

时间:2016-03-17 13:37:40

标签: python csv numpy dask

我想在Python中使用dask将csv导入数据帧时命名列。我使用的代码如下所示:

SSLContext sslContext = SSLContext.getDefault();
HostnameVerifier allowAll = new HostnameVerifier() {
    @Override
    public boolean verify(String hostName, SSLSession session) {
        return true;
    }
};
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
    .register("https", new SSLConnectionSocketFactory(sslContext, allowAll))
    .build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);

我想使用一个名为每列的数组:

  

names = ['tribute',                  'percent_countries_active',                  'num_wars',                  'num_tributes',                  '战争',                  'war_to_tribute_ratio',                  'US_wealth',                  'UK_wealth',                  'NZ_wealth'                 ]

这可以直接做吗?

1 个答案:

答案 0 :(得分:2)

只需使用names

read_csv参数即可
names = [...]
dd.read_csv(filename, header=None, names=names)

了解更多here