![](/img/trans.png)
[英]Python Pandas - Index' object has no attribute 'hour'
[英]Python pandas 'Index' object has no attribute 'str'
我正在嘗試運行此代碼,但它返回此錯誤
import pandas as pd
df = 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 '('
AttributeError:“索引”對象沒有屬性“ str”
我該如何解決? 我找不到
謝謝!
解決方法(在@Shijo的評論中發布)
df.index.to_series().str.split('\s\(')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.