question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setting column names has no effect

See original GitHub issue

I am doing a table join and would like to rename columns in the resulting table acs afterwards. So I set:

acs.columns = ["chr","start", "end", "rep1", "rep2"]

It allegedly works:

In [11]: acs.columns
Out[11]: ['chr', 'start', 'end', 'rep1', 'rep2']

But not really:

In [12]: acs.head()
Out[12]:
    chr  start    end  counts_x  counts_y
0  chr1  15765  17765         5         1
...

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
TomAugspurgercommented, Nov 6, 2015

@DSLituiev df = df.rename(columns=dict(zip(df.columns, new_columns))), slightly inconvenient but not too bad. dask has a few more things to track than pandas.

0reactions
mrocklincommented, Mar 24, 2017

It looks like this works now?

In [1]: import dask.dataframe as dd

In [2]: df = dd.demo.daily_stock('GOOG', '2008', '2010', freq='1s', 
   ...:                          random_state=1234)

In [3]: 

In [3]: df
Out[3]: 
Dask DataFrame Structure:
                       close     high      low     open
npartitions=505                                        
2008-01-02 09:00:00  float64  float64  float64  float64
2008-01-03 09:00:00      ...      ...      ...      ...
...                      ...      ...      ...      ...
2009-12-31 09:00:00      ...      ...      ...      ...
2009-12-31 16:00:00      ...      ...      ...      ...
Dask Name: from-delayed, 1010 tasks

In [4]: df.columns = list(map(str.upper, df.columns))

In [5]: df
Out[5]: 
Dask DataFrame Structure:
                       CLOSE     HIGH      LOW     OPEN
npartitions=505                                        
2008-01-02 09:00:00  float64  float64  float64  float64
2008-01-03 09:00:00      ...      ...      ...      ...
...                      ...      ...      ...      ...
2009-12-31 09:00:00      ...      ...      ...      ...
2009-12-31 16:00:00      ...      ...      ...      ...
Dask Name: rename, 1515 tasks

In [6]: df.head()
Out[6]: 
                       CLOSE     HIGH      LOW     OPEN
timestamp                                              
2008-01-02 09:00:00  692.889  692.889  692.840  692.871
2008-01-02 09:00:01  692.776  692.868  692.776  692.868
2008-01-02 09:00:02  692.737  692.818  692.737  692.797
2008-01-02 09:00:03  692.632  692.711  692.632  692.711
2008-01-02 09:00:04  692.521  692.637  692.521  692.637
Read more comments on GitHub >

github_iconTop Results From Across the Web

Renaming the column names of pandas dataframe is not ...
I am trying to rename the column names but it not working as expected. Code: mapping = {df.columns[0]:'Date', df.columns[1]: ...
Read more >
Setting Column Width Has No Effect - DataTables
I explicitly set the column names and widths but there is no effect on the column widths unless I set the CSS of...
Read more >
Pandas Change Column Names – 3 Methods
The second way to rename your columns is by setting DataFrame.columns to the list of your new column names. This will completely overwrite...
Read more >
Set column names to column value in pandas forloop, add ...
One reason this isn't working is because you are trying to assign a single value to df.columns. If you want to rename a...
Read more >
Renaming columns in a Pandas DataFrame | by B. Chen
In data analysis, we may work on a dataset that has no column names or column names contain some unwanted characters (e.g. space), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found