GithubHelp home page GithubHelp logo

Comments (4)

mixmixmix avatar mixmixmix commented on July 30, 2024 1

Hi @mixmixmix, I was able to reproduce what you provided. However, from my personal view, why not just use a dict instead of a Series? As stated in the documentation example, a dict might be more preferable.

Thanks @luke396 , and: yes absolutely using dicts makes more sense!. However, still if the option of using Series is possible, I think it should return an error if it cannot create a valid columns for the dataframe.

from pandas.

luke396 avatar luke396 commented on July 30, 2024

Hi @mixmixmix, I was able to reproduce what you provided. However, from my personal view, why not just use a dict instead of a Series? As stated in the documentation example, a dict might be more preferable.

import pandas as pd
import numpy as np

# Define a DataFrame
df = pd.DataFrame({
    'A': [1, 2, 3],
    'B': [4, 5, 6],
    'C': [7, 8, 9]
})

df.rename(columns={'A': 'X', 'B': 'Y', 'C': 'W'}, inplace=True, errors="raise")
#    X  Y  W
# 0  1  4  7
# 1  2  5  8
# 2  3  6  9

# Define a DataFrame of size 20x60
data = np.random.randint(1, 100, size=(20, 60))
columns = [f'Col_{i}' for i in range(60)]
df = pd.DataFrame(data, columns=columns)

# Create a Series for renaming columns, ensuring all names are unique except for two in the middle
new_names = [f'New_{i}' for i in range(61)]
old_names = [f'Col_{i}' for i in range(30)] + ['Col_29'] + [f'Col_{i}' for i in range(30, 60)]

df.rename(columns={old_names[i]: new_names[i] for i in range(61)}, inplace=True, errors="raise")
df['New_0']  # works

from pandas.

shoaib-moeen avatar shoaib-moeen commented on July 30, 2024

@luke396 I can look into this. If you want

from pandas.

luke396 avatar luke396 commented on July 30, 2024

@luke396 I can look into this. If you want

Of course, anyone can contribute to pandas. Replying 'take' will assign the issue to you.

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.