You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the only way to set a DataFrame's index column is by calling the set_index method on it.
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Age': [25, 30, 35, 40],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']
}
df = pd.DataFrame(data)
print(df)
Name Age City
0 Alice 25 New York
1 Bob 30 Los Angeles
2 Charlie 35 Chicago
3 David 40 Houston
df = df.set_index("Name")
print(df)
Age City
Name
Alice 25 New York
Bob 30 Los Angeles
Charlie 35 Chicago
David 40 Houston
Feature Description
I propose adding a new parameter to the Dataframe constructor: index_col.
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Age': [25, 30, 35, 40],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']
}
df = pd.DataFrame(data, index_col="Name")
print(df)
Age City
Name
Alice 25 New York
Bob 30 Los Angeles
Charlie 35 Chicago
David 40 Houston
With this addition you would be able to remove/change the default index column without having to call the set_index method, simplifying code. It would also make pandas overall more coherent as for example, the read_csv and read_excel, both return a DataFrame and already have this functionality in them.
To add upon this, I would also propose adding an index_col to the read_parquet function, working in a similar way.
Alternative Solutions
n/a
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion but I would be -1 on this feature. index_col seems to be highly tailored to when data is a mapping and wouldn't make much sense for other list-like data. I believe using set_index is an adequate alternative
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Currently, the only way to set a DataFrame's index column is by calling the set_index method on it.
Feature Description
I propose adding a new parameter to the Dataframe constructor:
index_col
.With this addition you would be able to remove/change the default index column without having to call the set_index method, simplifying code. It would also make pandas overall more coherent as for example, the read_csv and read_excel, both return a DataFrame and already have this functionality in them.
To add upon this, I would also propose adding an index_col to the read_parquet function, working in a similar way.
Alternative Solutions
n/a
Additional Context
No response
The text was updated successfully, but these errors were encountered: