in Education by
I have two Dataframes : DF1(That i've just resampled): Mi_pollution.head(): Sensor_ID Time_Instant Measurement 0 10273 2013-11-01 00:00:00 46 1 10273 2013-11-01 01:00:00 51 2 10273 2013-11-01 02:00:00 39 3 10273 2013-11-01 03:00:00 30 4 10273 2013-11-01 04:00:00 37 And I have the DF2 : Pollutants.head(): Sensor_ID Sensor_Street_Name Sensor_Lat Sensor_Long Sensor_Type UOM Time_Instant 0 20020 Milano -via Carlo Pascal 45.478452 9.235016 Ammonia µg/m YYYY/MM/DD 1 17127 Milano - viale Marche 45.496067 9.193023 Benzene µg/m YYYY/MM/DD HH24:MI 2 17126 Milano -via Carlo Pascal 45.478452 9.235016 Benzene µg/m YYYY/MM/DD HH24:MI 3 6057 Milano - via Senato 45.470780 9.197180 Benzene µg/m YYYY/MM/DD HH24:MI 4 6062 Milano - P.zza Zavattari 45.476089 9.143509 Benzene µg/m YYYY/MM/DD HH24:MI And What I'm trying to to do , is to create new columns based on the pollutants and add them to DF1 and assign each measurement based on the Sensor , like This: Sensor_ID Time_Instant Ammonia Benzene Nitrogene …... 0 20020 2013-12-01 00:00:00 4.8 Nan Nan 1 20020 2013-12-01 01:00:00 5.3 Nan Nan 2 20020 2013-12-01 02:00:00 3.0 Nan Nan . . 56 14330 2013-11-01 00:00:00 Nan 6.3 Nan 57 14330 2013-11-01 01:00:00 Nan 5.3 Nan . . Any Suggestion Would be much appreciated , Thank U all. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Assuming you're joining on Sensor_ID (there aren't any common Sensor_IDs between the two dataframes in the small example you gave), you could merge the dfs on Sensor_ID (and possibly Time_Instant?). Then you can use pivot_table to transpose the row values (Sensor_Type) to column headings, then fill in the row values with Measurement. For example: df3 = df1.merge(df2, on='Sensor_ID', how='left')\ .pivot_table(index=['Sensor_ID','Sensor_Street_Name','Other columns'], values='Measurement', columns='Sensor_Type')\ .reset_index()

Related questions

0 votes
    I want to select rows from a DataFrame based on values in some column in pandas, How can I do it? I ... WHERE column_name = some_value Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a dataframe with 2 columns and I want to add the new column; This new column should be updated based on ... +=1 is not working. Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I want to get the values of col1 in 3 different columns with separate headers. Date/Time col1 0 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have a dataset, say: DateJoined Name Number DateLeft 11/03/2015 Tom 001199 11/03/2019 11/03/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Background: I have an old web CMS that stored content in XML files, one XML file per page. I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    _________ extract a subset of rows from a dataframe based on logical conditions. (a) rename (b) filter (c ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have this dataframe and trying to select the last n (=2) rows if the present value is True so I code as ... , I should select 50,40 Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how I can represent the equivalent of an Enum in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a dataframe with which if a cell has a value other than "." then I need python to return ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    >>> a=[1,2,3] >>> a.remove(2) >>> a [1, 3] >>> a=[1,2,3] >>> del a[1] >>> a ... above three methods to remove an element from a list? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    In _______________ index instead of storing all the columns for a record together, each column is stored ... topic in portion Indexing and Hashing of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I asked a question like this here: How to adjust Label in tkinter? But the events load up and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I used the function for gower distance from this link: https://sourceforge.net/projects/gower-distance- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm creating my first program on python. The objective is to get an output of trip cost. In the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
...