Python Forum
Transposing a dataframe without creating NaN values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transposing a dataframe without creating NaN values
#1
Hi! I have the data like this in a .csv file:
index data
1 10
2 20
3 30
4 40
5 50
6 10
2 20
3 30
4 40
5 50
6. 60

And I would need them to be read like this in Python:
1 2 3 4 5 6
10 20 30 40 50 60
10 20 30 40 50 60

But it transposes the values and NaN appears between them as if it were 0 in a matrix:
1 2 3 4 5 6
10 NaN NaN NaN NaN. NaN
NaN 20 NaN NaN NaN NaN
NaN NaN 30 NaN NaN NaN
NaN NaN NaN 40 NaN NaN
NaN NaN NaN NaN 50 NaN
NaN NaN NaN NaN NaN 60
Reply


Messages In This Thread
Transposing a dataframe without creating NaN values - by doug2019 - Mar-17-2023, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,589 Jul-27-2022, 08:50 PM
Last Post: rob101
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,238 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  List of dataframe values beginning with x,y or z glidecode 3 2,008 Nov-08-2021, 10:16 PM
Last Post: glidecode
  How to sort values descending from a row in a dataframe using python sankarachari 1 1,471 Aug-16-2021, 08:55 AM
Last Post: jamesaarr
  How to get value in Dataframe given row & column values? moonlight 1 2,482 Apr-26-2021, 09:30 PM
Last Post: Larz60+
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,618 Mar-09-2021, 12:24 PM
Last Post: KMV
  Dataframe extract key values danipyth 0 1,710 Feb-07-2021, 03:52 PM
Last Post: danipyth
  Assigning Column nunique values to another DataFrame column Pythonito 1 1,934 Jun-26-2020, 06:52 AM
Last Post: hussainmujtaba
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 2,193 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92
  Creating a new DataFrame from another DataFrame column Ilangos 1 2,134 Jun-05-2019, 09:47 AM
Last Post: Ilangos

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020