Python Forum
Insert into sublist if sublist is not having same no of records.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert into sublist if sublist is not having same no of records.
#4
Have tried some thing like below but it did not return my result
Had my data in pandas and tried, but no luck

>>> df
    SalesamountQuota  CalendarYear  Employeekey
0            28000.0          2010          272
1           308000.0          2011          272
2           582000.0          2012          272
3           387000.0          2013          272
4           367000.0          2010          281
5          3037000.0          2011          281
6          4822000.0          2012          281
7          2936000.0          2013          281
8           637000.0          2010          282
9          3440000.0          2011          282
10          478000.0          2010          296
11        12090000.0          2012          296

df_emp =df[['CalendarYear','Employeekey']]
emp=df['Employeekey'].unique()
empnew=pd.DataFrame(data=emp.flatten())
empnew.columns =['Employeekey']
for i in empnew:
    pd.merge(df_emp,df,left_on='Employeekey', right_on='CalendarYear',how='right')
Reply


Messages In This Thread
RE: Insert into sublist if sublist is not having same no of records. - by parthi1705 - May-10-2019, 11:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use one list as search key for another list with sublist of list jc4d 4 2,221 Jan-11-2022, 12:10 PM
Last Post: jc4d
Question Sublist/ Subarray into string Python SantiagoPB 2 2,171 Apr-23-2021, 07:03 PM
Last Post: SantiagoPB
  List of objects with sublist medatib531 4 2,372 Mar-01-2020, 06:16 PM
Last Post: buran
  Split List and Sublist from Pyodbc parthi1705 1 2,259 May-05-2019, 10:44 AM
Last Post: Larz60+
  merging sublist into single list in python abhishek8singhai 8 9,610 Mar-22-2019, 11:46 PM
Last Post: micseydel
  Can I use a sublist as an argument in python? MartinBerlin 3 4,069 Aug-25-2018, 10:46 AM
Last Post: buran
  Insert using psycopg giving syntax error near "INSERT INTO" olgethorpe 4 15,737 Jul-21-2017, 07:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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