5

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:

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' ]

Is this possible to do directly?

Jim Caton
  • 111
  • 2
  • 5

1 Answers1

5

Just use the names argument for the read_csv

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

Read more here

Sevanteri
  • 3,749
  • 1
  • 23
  • 27
  • Thanks. The error was that the number of columns in names didn't match the number of elements in the csv. – Jim Caton Mar 17 '16 at 15:28