docx
I've changed my code as
df = pd.read_csv('sample.csv', engine='python')
df.columns = [col for col in df.columns if col!= "Col1"]
df.rename(columns = {'Col1': 'Last_Name', 'Col2': 'First_Name'}, inplace=True)
df.drop(df.index, inplace=True)
df.columns = ['Col1','Col2']
df.index = pd.to_datetime(df.index)
print(df)
A:
You can do it in two steps:
import pandas as pd
df = pd.DataFrame({'Col1':['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9'],
'Col2':['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9']},
index=pd.to_datetime(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04', '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08', '2017-01-09']),
columns=['Col1','Col2'])
Col1 Col2
2017-01-01 B1 B2
2017-01-02 A2 B2
2017-01-03 A3 B2
2017-01-04 A4 B2
2017-01-05 A5 B2
2017-01-06 A6 B2
2017-01-07 A7 B2
2017-01-08 A8 B2
2017
Related links:
Comments