First time here? Checkout the FAQ!
x
0 votes
1.3k views
asked in General by (210 points)  

Dataframe looks like below

image

I have dataframe like above. which I want to a~t reshape (a~t, 1)

I want to reshape dataframe like below ( b~t column is go to under the a column)

날짜 역번호 역명 구분 a

2018-01-01 150 서울역 승차 379

2018-01-01 150 서울역 승차 287

2018-01-01 150 서울역 승차 371

2018-01-01 150 서울역 승차 876

2018-01-01 150 서울역 승차 965

....

2008-01-01 152 종각 승차 2920

2008-01-01 152 종각 승차 2290

2008-01-01 152 종각 승차 802

2008-01-01 152 종각 승차 1559

like df = df.reshape(len(data2)*a~t, 1)

i tried pd.melt but It does not work well.

df2 = pd.melt(df, id_vars=["날짜", "역번호", "역명", "구분"], value_name="t")

is remove b ~ t but i want insert b~t behind a

dataset is https://drive.google.com/file/d/1Upb5PgymkPB5TXuta_sg6SijwzUuEkfl/view?usp=sharing

  

1 Answer

0 votes
answered by (116k points)  

Did you try to use reshape(-1,1)

a = np.array([[1, 2, 3, 4],
         [5, 6, 7, 8],
         [9, 10, 11, 12]])
print(a.shape)
# output: (3, 4)

print(a.reshape(-1,1))
'''
output:
array([[ 1],
   [ 2],
   [ 3],
   [ 4],
   [ 5],
   [ 6],
   [ 7],
   [ 8],
   [ 9],
   [10],
   [11],
   [12]])
'''
...