Accommodate DataFrames with numeric column names
See original GitHub issueAs demonstrated in the example from this stack overflow response, when converting a NumPy array into a Dataframe, the column labels are initially numeric. When trying to index by these column labels, I realized the backend DataFrame indexing is using the attribute method, df.column_label
, and not the df[column_label]
method. The current method supports less variation in column label in that it only supports valid python identifiers, e.g., column labels cannot be purely numeric. This Pandas’ doc page has more details. If possible, changing to the [ ]
method (or __getitem__ method
) would allow for a wider range of inputs, thereby simplifying the user experience.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
how to get numeric column names in pandas dataframe
Use select_dtypes with np.number for select all numeric columns: df = pd.DataFrame({'A':list('abcdef'), 'B':[4.5,5,4,5,5,4], 'C':[7.4,8,9,4 ...
Read more >Essential basic functionality — pandas 1.5.2 documentation
Passing a dictionary of column names to a scalar or a list of scalars, to DataFrame.agg allows you to customize which functions are...
Read more >Solved Read in the dataset into a dataframe. Keep only the
Question: Read in the dataset into a dataframe. Keep only the belowcolumns. Make sure the numeric columns are in the correct datatype.
Read more >Simple guide to combine dataframes using pandas
As we can see above, we can initiate column names using column keyword inside DataFrame method with syntax as pd.DataFrame(values, column).
Read more >Extract or Replace Parts of a Data Frame - R
i, j, elements to extract or replace. i, j are numeric or character or, ... Similarly, column names will be transformed (if columns...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
[A PR would hurry this process along, by the way! 😃]
I tested the code as it is (without the change made by pr #285), and it did take column names that would not work with the
df.col_name
syntax, e.g.,df['x values']
. It seems the real issue was it did not take numeric column names, which #285 fixes (small change as it is).