Skip to main content

All Questions

Tagged with
1 vote
1 answer
56 views

Reshape Pandas Dataframe and group by 2 level columns

I have a dataframe with flat structure of having unique Rows as follow. I need to reshape it as shown below. Using Pivot table and swapping levels, I managed to obtain somewhat closer to the result, ...
rush dee's user avatar
  • 336
0 votes
1 answer
46 views

this code show an reshape error. how fix this?

I'm new in python and ML. I wrote this code for practicing. It displays this error. how do I solve this reshape problem? import pandas as pd import sklearn as skl data=pd.read_csv('housing.csv') ...
Vahid Agha ahmadi's user avatar
0 votes
0 answers
48 views

Pandas move levels of a composite column as a value

Let's imagine as a starting point I have a dataframe, similar to the one below (using a tuple for the composite columns): Index, (ATop,AMiddle,ABottom,filt1_1, filt2_1), (ATop,AMiddle,ABottom,filt1_2,...
georgi koyrushki's user avatar
0 votes
1 answer
42 views

cannot reshape array of size 4 into shape (4,4) in DataFrame where clause

Can anyone explain to me what is going on? Here's the piece of code. If I have the DataFrame of precisely length 4, the statement in the try clause throws an exception. If I make the dataframe of any ...
user23873134's user avatar
0 votes
0 answers
43 views

Is there a more effective way to create new columns from row values in a Pandas DataFrame? [duplicate]

Given a dataframe with three initial columns, one of which has categorical type with two categories, the aim is to create distinct columns for each category and subsequently store within them the ...
ciranzo's user avatar
  • 57
1 vote
3 answers
143 views

Reshape a stacked style data file into a dataframe using pandas

I have a csv input file with the below format and i'm looking for a fairly easy way to convert to normal shape dataframe in pandas. the csv data file has all data stacked up into two columns with each ...
Hannibal's user avatar
  • 105
-1 votes
1 answer
152 views

ValueError: Expected 2D array

I try to make a SVC. from sklearn.svm import SVC import numpy as np import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("iris.csv") df.loc[df["species"]=="...
Joo's user avatar
  • 37
0 votes
1 answer
68 views

reshape problem in LogisticRegression code

I try to make a LogisticRegression. import pandas import matplotlib.pyplot as plt from sklearn.linear_model import LogisticRegression import numpy as np df = pd.read_csv("tested.csv") df....
Joo's user avatar
  • 37
0 votes
1 answer
90 views

reshaping rows and columns and then converting to numpy array

Following DataFrame contains integer values. I want them to reshaped into a new column where every row will be represented, as a combination of each 3 rows of each columns from old dataframe. import ...
Rupak's user avatar
  • 39
0 votes
2 answers
112 views

fit function expected 2D array, got 1D array instead

I am using Linear Regression to predict the 'Value' throughout the years, I have the following data, i imported from a csv file : **df.head()** : LOCATION INDICATOR SUBJECT MEASURE FREQUENCY ...
Najoua's user avatar
  • 401
0 votes
1 answer
105 views

How can I rearrange df as the nodes index in pytorch geometric manner?

I'd like to rearrange my dataframe (data) as the node index to the original name in pytorch geometric manner for extracting node embedding. import pandas as pd data = {'Source': ['Rainfall', 'SP2', '...
Ponlok Peter's user avatar
0 votes
0 answers
39 views

Reshape/Reposition dataframe using pandas [duplicate]

I have a dataframe df as following: I want to reshape/reposition from df into df2 as following: I have tried, but it gave a strange result (please see my code) Appreciate any suggestions here. # ...
Ponlok Peter's user avatar
0 votes
2 answers
79 views

Narrow to wide data

I have a following Data frame (df) as shown below: Is it possible to reshape my (df) into (df1) as shown below: I have provided a sample of my code, but it does not work. Appreciate any through or ...
Ponlok Peter's user avatar
1 vote
3 answers
58 views

to check the values of different and columns and if matching then assigned to the rows

Suppose I have the following columns for a dataframe (1, 2, 3, 4): Column1 value: ('Curl Care Anti-Hairfall 200ml', 'Curl Care Clean 200ml', 'Curl Care Color Protect 200ml') Column2 value: ('Curl ...
shubham's user avatar
  • 13
1 vote
3 answers
72 views

Reshaping a Dataframe with repeating column names

I have data that looks like this: dataframe_1: week SITE LAL SITE LAL 0 1 BARTON CHAPEL 1.1 PENASCAL I 1 1 2 BARTON CHAPEL 1.1 PENASCAL I 1 2 3 ...
user2100039's user avatar
  • 1,356

15 30 50 per page
1
2 3 4 5
28