1,730 views
0 0 votes

Dataframe looks like below

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_id="gdev-id-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

0% Accept Rate Accepted 0 answers out of 3 questions

1 Answer

0 0 votes

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]])
'''

Related questions

1 1 vote
1 answers 1 answer
1.5k
1.5k views
interview asked Dec 24, 2019
1,543 views
Consider the Pandas DataDrame df below. Filter it appropriately so that it outputs the shown results.gh owner language repo stars 0 pandas-dev python pandas 17800 1 tidyv...
0 0 votes
0 0 answers
549
549 views
Anas asked Nov 28, 2021
549 views
So say I have a column with categorical data like different styles of temperature: 'Lukewarm', 'Hot', 'Scalding', 'Cold', 'Frostbite',... etc.I know that we can use pd.ge...
6 6 votes
1 1 answer
701
701 views
Neo asked Sep 19, 2018
701 views
Hello,If someone can post the video tutorial for Pandas, Numpy and Matplotlib. I would appreciate it. I know that Lynda.com has those videos but I still have to get my Li...
1 1 vote
1 1 answer
743
743 views
1 1 vote
1 answers 1 answer
825
825 views
kakalotka asked Feb 6, 2021
825 views
I have a hard time distinguishing terminologies of SparkSQL. While SparkSQL are quite flexible in terms of abstraction layers, its really difficult for beginner to naviga...