简体   繁体   English

如何获取 pandas dataframe 中标题的“Excel”列名称?

[英]How to get "Excel" column name for headers in pandas dataframe?

I have a csv file that has 480 columns and one row which has the header's name.我有一个 csv 文件,它有 480 列和一行具有标题名称。 I want to get the excel column name for a specific header.我想获取特定 header 的 excel 列名。 for eg-例如-

var1 var2 event5 event8 media5 retail6 event9 var10 var1 var2 事件5 事件8 媒体5 零售6 事件9 var10

Let's say, I need to locate the excel column namefor retail6(F Column in Excel).比方说,我需要找到 excel 列名称用于零售 6(Excel 中的 F 列)。 what is the best and easiest way of doing that?最好和最简单的方法是什么?

output should be- var1 A var2 B event5 C and so on output 应该是 var1 A var2 B event5 C 等等

I think this answer might be the one you are looking for: stackoverflow.com/a/31328974/13734132我认为这个答案可能是您正在寻找的答案:stackoverflow.com/a/31328974/13734132

new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header #set the header row as the df header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM