import pandas as pd
import numpy as np
test_df = {year:{'col_A': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
} for year in range(2008, 2012)}
test_df = pd.DataFrame(test_df)
print(test_df.columns)
print(test_df.index)
Int64Index([2008, 2009, 2010, 2011], dtype='int64')
Index(['col_A', 'col_B'], dtype='object')
import pandas as pd
import numpy as np
test_df = {year:{'col_A': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
} for year in range(2008, 2012)}
test_df = pd.DataFrame(test_df)
test_df = test_df.T
print(f"columsn: {test_df.columns}")
print(f"index: {test_df.index}")
columsn: Index(['col_A', 'col_B'], dtype='object')
index: Int64Index([2008, 2009, 2010, 2011], dtype='int64')
import pandas as pd
import numpy as np
test_df = {year:{'col_A': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
'col_B': np.random.randint(1, 100, size=10),
} for year in range(2008, 2012)}
test_df = pd.DataFrame.from_dict(test_df, orient='index')
print(f"columns: {test_df.columns}")
print(f"index: {test_df.index}")
댓글남기기