Ich versuche, diesen Code zu laufen, aber es gibt diesen Fehler zurückPython Pandas ‚Index‘ Objekt hat kein Attribut ‚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: 'Index' object has no attribute 'str'
Wie kann ich es lösen? Ich kann es nicht finden.
Vielen Dank!
df.index ist ein numpy Array, kein Pandas Series (und so kann die Methode Series.str.split verwenden) – cmaher
Try df .index.to_series(). str.split ('\ s \ (') – Shijo
Danke !, es funktioniert! – cluna