请叫我攻城狮hh 2020-12-10 19:02 采纳率: 0%
浏览 25

小白求助! Python 行列的处理

各位大神好
我在做项目练习时遇到这个代码
来自 https://en.wikipedia.org/wiki/All-time_Olympic_Games_medal_table


import pandas as pddf = pd.read_csv('olympics.csv', index_col=0, skiprows=1)
for col in df.columns:   
   if col[:2]=='01':        
         df.rename(columns={col:'Gold'+col[4:]}, inplace=True)   
   if col[:2]=='02':        
         df.rename(columns={col:'Silver'+col[4:]}, inplace=True)   
   if col[:2]=='03':        
         df.rename(columns={col:'Bronze'+col[4:]}, inplace=True)   
    if col[:1]=='№':      
 
          df.rename(columns={col:'#'+col[1:]}, inplace=True)
     names_ids = df.index.str.split('\s\(') # split the index by '('df.index = names_ids.str[0] # the [0] element is the country name (new index) df['ID'] = names_ids.str[1].str[:3] # the [1] element is the abbreviation or ID (take first 3 characters from that)df = df.drop('Totals')df.head()

我自己看了很久 可是就是不知道加粗部分的操作是什么含义
求大神帮忙指点迷津啊
万分感激

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 hanzi-writer生成的svg外有一层div,修改div宽高影响的是画布大小,字体在不同视口下完全不相同。我想要让字体跟画布同比例大小该怎么实现?
      • ¥15 Java集合多对一问题集
      • ¥20 PowerShell如何操作记事本?
      • ¥15 intel网卡固件降级失败
      • ¥20 html使用模型的问题
      • ¥15 这些怎么解题啊来个人
      • ¥15 h5套壳IOS Cordova依赖找不到导致编译失败
      • ¥15 分组密码算法misty1的子密钥生成算法c++实现
      • ¥15 vscode的一些报错,希望可以得到解决
      • ¥15 这代码我服了,我需要一个每隔10秒响一次的软件