1st table is my input table present in 1 data frame and 2nd table is my result table. can some one please help how to solve this using python [1]: https://i.stack.imgur.com/CJzgW.jpg
Asked
Active
Viewed 31 times
0
-
1Hey there, I would like you to take the [tour](https://stackoverflow.com/tour) and go through [how do I ask](https://stackoverflow.com/help/how-to-ask), and make the necessary changes. Its always a good practice to show your research so far and work related to the question if necessary as opposed to asking the community to write the code based on your requirement. – astqx Jan 19 '21 at 14:26
1 Answers
0
Try:
df.groupby('Hr')[['Apps', 'Record_Count', 'Records_Per_Sec']].apply(lambda x: x.set_index('Apps').T.unstack())
Apps A B C
Record_Count Records_Per_Sec Record_Count Records_Per_Sec Record_Count Records_Per_Sec
Hr
0-1 60 1 60 1 60 1

Pygirl
- 12,969
- 5
- 30
- 43
-
@Pygirl-- Thanks.. I have tried with this code but getting below error ERROR --- > PEP 263 -- Defining Python Source Code Encodings. What T refers to in lamda code part? – Mohamed Haneef Jan 19 '21 at 15:35
-
-
The issue is with your data. https://stackoverflow.com/a/6289494/6660373 please follow the solution. For the data you have provided this is the solution that I have given. – Pygirl Jan 19 '21 at 15:40
-
Encoding error resolved and attribute error df1 = df.groupby('Hr'),['Apps','record_count','Records_per_sec'].apply(lambda x: x.set_index('Apps').T.unstack())..... getting below error. AttributeError: 'list' object has no attribute 'apply' – Mohamed Haneef Jan 19 '21 at 19:04
-
Add the dataframe and the whole traceback to the post.. btw syntax is wrong. Please check your syntax. Why there is comma after groupby('Hr') – Pygirl Jan 19 '21 at 20:23
-
df = tableitem.select("Hr","Apps", "record_count", "Records_per_sec") Error: df1 = df.groupby('Hr')[['Apps','record_count','Records_per_sec']].apply(lambda x: x.set_index('Apps').T.unstack()) TypeError: 'GroupedData' object has no attribute '__getitem__' – Mohamed Haneef Jan 20 '21 at 07:29
-
Can you show me what exactly you are doing? Because I can't see the problem with the solution provided on the given data. Invite me in chat and show me the screenshot. – Pygirl Jan 20 '21 at 07:53