Questions tagged [lreshape]

Undocumented pandas function.

Reshape long-format data to wide. Generalized inverse of DataFrame.pivot.

Documentation is only in github.

8 questions
17
votes
4 answers

reshape a pandas dataframe

suppose a dataframe like this one: df = pd.DataFrame([[1,2,3,4],[5,6,7,8],[9,10,11,12]], columns = ['A', 'B', 'A1', 'B1']) I would like to have a dataframe which looks like: what does not work: new_rows = int(df.shape[1]/2) * df.shape[0] new_cols…
Moritz
  • 5,130
  • 10
  • 40
  • 81
2
votes
2 answers

Pandas: Multiple columns containing Names and Values of Variables: How to use Pivot?

i am not sure if, and how i can do the following transformation: I have a DataFrame looking like this: Index Name detail1 detail1_value detail2 detail2_value detail3 detail3_value 1 Albert Age 30 Group A …
Big.Joe
  • 85
  • 8
2
votes
3 answers

Rearranging dataframe dimensions

I have a df with lots of columns : date risk lev chemical weight date risk lev chemical weight 15-5-16 5 Potasium 5mg 15-5-16 3 Sodium 7 mg 14-5-16 6 Potasium 10mg 14-5-16 2 …
JamesHudson81
  • 2,215
  • 4
  • 23
  • 42
2
votes
3 answers

Pandas stack column pairs

I have a pandas dataframe with about 100 columns of following type: X1 Y1 X2 Y2 X3 Y3 0.78 0.22 0.19 0.42 0.04 0.65 0.43 0.29 0.43 0.84 0.14 0.42 0.57 0.70 0.59 0.86 0.11 …
Zanam
  • 4,607
  • 13
  • 67
  • 143
0
votes
0 answers

ValueError: Expected 2D array, got 1D array instead: array=[4. 4. 3. ... 3. 3. 3.]

I tried to find cosine_similarity that compare pivot table and object using .loc, and the result says ValueError: Expected 2D array, got 1D array instead: array=[4. 4. 3. ... 3. 3. 3.]. Reshape your data either using array.reshape(-1, 1) if your…
0
votes
1 answer

Python - simple dataframe restructuring

I am struggling to restructure my dataframe in a simple and effective way. The first dataframe 'new' is what I have and the desired dataframe is new2. I have been messing around with pivot, stack, unstack, set_index, reshape etc for a long time and…
Ludo
  • 2,307
  • 2
  • 27
  • 58
0
votes
1 answer

Python sklearn polynomial preprocessing and dimensional problems

I am experimenting the fit of 1-3 degree polynomial transformation to the original data using 100 predicted values each. I first 1) reshaped the original data, 2) applied fit_transform on the test set and prediction space (of data features), 3)…
Chris T.
  • 1,699
  • 7
  • 23
  • 45
-2
votes
1 answer

Python Pandas rows values convert to columns values

I use Python pandas read dataframe like this: