• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Transforming a DataFrame

Resolved: Transforming a DataFrame

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I got a DataFrame looks like this (call it df1):
I need to convert the value to a matrix for calculation, so I think I need to transform the DataFrame to this form (call it df2) first (and then convert to a numpy array):
if an id don’t have value on a day, just set that day’s value to 0 (and probably none of the ids have a full-date value).
What I think is to generate an empty DataFrame (call it df3) first and then fill df1’s data in it:
But I don’t know the proper way to iterate df1’s value to match the cell in df3 (And people say it’s a bad idea to iterate a dataframe ?), or is there a better approach (like pivot or merge)?

Answer:

This should work.

If you have better answer, please add a comment about this, thank you!

dataframe pandas python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: what are the permissions required to assign a resource monitor to a warehouse?

01/04/2023

Resolved: How can I modify formData before sending it?

01/04/2023

Resolved: How to efficient create SimpleITK image?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.