Python Forum
Creating a new DataFrame from another DataFrame column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a new DataFrame from another DataFrame column
#1
Hi All,

I'm newbie to python. I've a task to automate wherein I have to create separate excel files based on the RTO code available in an excel sheet using the main data available in another excel sheet.

import pandas as pd
import xlrd

Rto_Main_Sheet = pd.read_excel("D:\Testing_MIS\Auto_Task\FINAL GLM SHEET.xlsx",sheet_name='Jeep tata mahindra')
Rto_Main_Sheet.head(5)
Output:
ID Combined - TA100 RTO Code Age Discount 0 1 FICH AN01 0 50 1 2 FIWR AN01 0 50 2 3 FIRN AN01 0 50 3 4 FICO AN01 0 50 4 5 JPWR AN01 0 70
Rto_Code = pd.read_excel("D:\Testing_MIS\Auto_Task\RTO_Code_AN01-HP46.xlsx",sheet_name='RTO_Code_AN01-HP46')
Rto_Code.head(5)
Output:
RTO 0 AN01 1 AN02 2 AP01 3 AP02 4 AP03
[/python]

Now, for each RTO Code available have to create a separate DataFrame and write it to excel file. The output should be as follows:-
Here, only the RTO Code has to be changed and rest all the data of the column would be as is from the Rto_Main_Sheet dataframe.

Output:
ID Combined - TA100 RTO Code Age Discount 0 1 FICH AN02 0 50 1 2 FIWR AN02 0 50 2 3 FIRN AN02 0 50 3 4 FICO AN02 0 50 4 5 JPWR AN02 0 70
Any sort of assistance or help is much appreciated.

Thank you in advance.
Reply


Messages In This Thread
Creating a new DataFrame from another DataFrame column - by Ilangos - Jun-04-2019, 11:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries sawtooth500 14 591 Apr-24-2024, 01:42 AM
Last Post: sawtooth500
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 467 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Dataframe copy warning sawtooth500 4 393 Mar-25-2024, 11:38 PM
Last Post: sawtooth500
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries i sawtooth500 3 1,448 Mar-22-2024, 03:08 AM
Last Post: deanhystad
  Adding PD DataFrame column bsben 2 342 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 767 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Comparing Dataframe to String? RockBlok 2 439 Nov-24-2023, 04:55 PM
Last Post: RockBlok
  Filter data into new dataframe as main dataframe is being populated cubangt 8 1,037 Oct-23-2023, 12:43 AM
Last Post: cubangt
  DataFRame.concat() nafshar 3 813 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Convert dataframe from str back to datafarme Creepy 1 652 Jul-07-2023, 02:13 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020