How i can make from this DataFrame:
(try df.drop([0]), df.iloc[1:]
but dont work)
A B C
0 1 2 3
1 X Y Z
this:
1 2 3
0 X Y Z
How i can make from this DataFrame:
(try df.drop([0]), df.iloc[1:]
but dont work)
A B C
0 1 2 3
1 X Y Z
this:
1 2 3
0 X Y Z
in two steps,
df.columns = df.iloc[0]
df = df.iloc[1:].reset_index(drop=True)
print(df)
1 2 3
0 X Y Z
a better method would be to use skiprows
in your read argument.
from io import StringIO
d = """ A B C
1 2 3
X Y Z"""
df = pd.read_csv(StringIO(d),sep='\s+',skiprows=1)
print(df)
1 2 3
0 X Y Z
IIUC, DataFrame.transpose
and DataFrame.set_index
df.T.set_index(0).T.reset_index(drop=True).rename_axis(columns=None)
1 2 3
0 X Y Z