Since the recent shipping settings change (made by Amazon, not us), we have been having some problems with our _POST_FLAT_FILE_INVLOADER_DATA_ feed (and have made no changes our end).
Below is an example feed sent (the spaces are tabs, it just shows like this here):
sku product-id product-id-type price minimum-seller-allowed-price maximum-seller-allowed-price item-condition quantity add-delete will-ship-internationally expedited-shipping item-note fulfillment-center-id merchant-shipping-group-name
7564 B003TL29BU 1 16.46 11 518 a 3 3
7648 B003R7JSKG 1 57.52 11 54 a 3 3
11544 B003ZGF7NG 1 5.30 11 0 a 3 3
12144 B001LJA5AO 1 5.11 11 331 a 3 3
13099 B004WJ0KIC 1 17.88 11 330 a 3 3
20700 B00G9EQP3M 1 6.30 11 300 a 3 3
20931 B0012TUWQA 1 5.73 11 610 a 3 3
20932 B002EDNJHM 1 6.20 11 6 a 3 3
20934 B002DKRF2Q 1 12.20 11 610 a 3 3
21031 B007YZMGYW 1 8.15 11 601 a 3 3
21033 B00FEFMLFS 1 9.97 11 610 a 3 3
21034 B00FEFMLWQ 1 17.88 11 305 a 3 3
21036 B00FEFMMCU 1 29.96 11 302 a 3 3
21046 B011AFU39G 1 13.92 11 309 a 3 3
23382 B0085N3K4M 1 10.64 11 303 a 3 3
23421 B0080N6OKE 1 16.02 11 300 a 3 3
25633 B0033XDZJY 1 5.84 11 10 a 3 3
25634 B008719D70 1 7.67 11 309 a 3 3
25635 B007YZRQ4C 1 5.67 11 6 a 3 3
25636 B007YZRQNI 1 7.97 11 310 a 3 3
25657 B00803CXKO 1 9.89 11 17 a 3 3
25658 B00871OCCQ 1 18.59 11 7 a 3 3
25666 B007YZLUVW 1 7.10 11 310 a 3 3
26324 B003FTU1W0 1 6.98 11 308 a 3 3
29377 B0042MI6AS 1 32.81 11 330 a 3 3
29379 B004WJ0L3Q 1 20.97 11 628 a 3 3
29380 B004WJ0KVE 1 22.88 11 331 a 3 3
29381 B004WJ0H9O 1 20.95 11 330 a 3 3
29382 B004WJ0HEE 1 21.25 11 330 a 3 3
29383 B004WJ0HPI 1 19.30 11 630 a 3 3
29384 B004WJ0HVM 1 19.30 11 330 a 3 3
29385 B004WJ0I20 1 21.97 11 630 a 3 3
29387 B004WJ0II4 1 27.24 11 330 a 3 3
29388 B004WJ0IPM 1 27.24 11 630 a 3 3
29389 B004WJ0IUC 1 37.02 11 330 a 3 3
29390 B004WJ0KAU 1 32.88 11 330 a 3 3
32230 B004WDOTV2 1 25.57 11 64 a 3 3
37048 B00JUYP6DS 1 26.35 11 30 a 3 3
37927 B00P06NFF6 1 5.77 11 310 a 3 3
39949 B003ESMDOG 1 5.20 11 53 a 3 3
41208 B00KOI8NU2 1 8.17 11 30 a 3 3
41944 B00N99CWIM 1 14.34 11 60 a 3 3
42006 B00PITPZI0 1 21.53 11 82 a 3 3
45015 B00NIT9L9G 1 11.24 11 31 a 3 3
49224 B00PIUNSJC 1 14.21 11 31 a 3 3
71765 B007G9AJJU 1 16.43 11 2 a 3 3
And below here is the output of the errors from Amazon. We don't really understand why shipping options would suddenly be invalid and are not actually specifying any shipping options in the feed anyway.
Feed Processing Summary:
Number of records processed 46
Number of records successful 4
original-record-number sku error-code error-type error-message
1 7564 8005 Error You are attempting to change an identity attribute for this SKU. To proceed, please delete this SKU and recreate the SKU with the appropriate identity attribute. For more information and detailed instructions, see: http://sellercentral.amazon.co.uk/gp/help/23191
1 7564 13013 Error This SKU does not exist in your Amazon inventory so we could not process this record. To correct this error for future feeds, add the SKU to your Amazon account. For more information, see http://sellercentral.amazon.co.uk/gp/errorcode/13013.
1 7564 33033 Error Ship option 'Exp UK Domestic' is invalid.
1 7564 33033 Error Ship option 'Std UK Domestic' is invalid.
1 7564 33033 Error Ship option 'Std UK Europe' is invalid.
1 7564 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
1 7564 33033 Error Ship option 'Std UK-ROW' is invalid.
10 21031 33033 Error Ship option 'Exp UK Domestic' is invalid.
10 21031 33033 Error Ship option 'Std UK Domestic' is invalid.
10 21031 33033 Error Ship option 'Std UK Europe' is invalid.
10 21031 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
10 21031 33033 Error Ship option 'Std UK-ROW' is invalid.
11 21033 33033 Error Ship option 'Exp UK Domestic' is invalid.
11 21033 33033 Error Ship option 'Std UK Domestic' is invalid.
11 21033 33033 Error Ship option 'Std UK Europe' is invalid.
11 21033 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
11 21033 33033 Error Ship option 'Std UK-ROW' is invalid.
12 21034 33033 Error Ship option 'Exp UK Domestic' is invalid.
12 21034 33033 Error Ship option 'Std UK Domestic' is invalid.
12 21034 33033 Error Ship option 'Std UK Europe' is invalid.
12 21034 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
12 21034 33033 Error Ship option 'Std UK-ROW' is invalid.
13 21036 33033 Error Ship option 'Exp UK Domestic' is invalid.
13 21036 33033 Error Ship option 'Std UK Domestic' is invalid.
13 21036 33033 Error Ship option 'Std UK Europe' is invalid.
13 21036 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
13 21036 33033 Error Ship option 'Std UK-ROW' is invalid.
14 21046 33033 Error Ship option 'Exp UK Domestic' is invalid.
14 21046 33033 Error Ship option 'Std UK Domestic' is invalid.
14 21046 33033 Error Ship option 'Std UK Europe' is invalid.
14 21046 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
14 21046 33033 Error Ship option 'Std UK-ROW' is invalid.
15 23382 8101 Error Invalid ProductType value for SKU: [23382]. For help fixing this, see http://sellercentral.amazon.co.uk/gp/errorcode/8101
16 23421 8101 Error Invalid ProductType value for SKU: [23421]. For help fixing this, see http://sellercentral.amazon.co.uk/gp/errorcode/8101
16 23421 13013 Error This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.co.uk/gp/errorcode/13013
17 25633 33033 Error Ship option 'Exp UK Domestic' is invalid.
17 25633 33033 Error Ship option 'Std UK Domestic' is invalid.
17 25633 33033 Error Ship option 'Std UK Europe' is invalid.
17 25633 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
17 25633 33033 Error Ship option 'Std UK-ROW' is invalid.
18 25634 33033 Error Ship option 'Exp UK Domestic' is invalid.
18 25634 33033 Error Ship option 'Std UK Domestic' is invalid.
18 25634 33033 Error Ship option 'Std UK Europe' is invalid.
18 25634 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
18 25634 33033 Error Ship option 'Std UK-ROW' is invalid.
19 25635 33033 Error Ship option 'Exp UK Domestic' is invalid.
19 25635 33033 Error Ship option 'Std UK Domestic' is invalid.
19 25635 33033 Error Ship option 'Std UK Europe' is invalid.
19 25635 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
19 25635 33033 Error Ship option 'Std UK-ROW' is invalid.
2 7648 33033 Error Ship option 'Exp UK Domestic' is invalid.
2 7648 33033 Error Ship option 'Std UK Domestic' is invalid.
2 7648 33033 Error Ship option 'Std UK Europe' is invalid.
2 7648 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
2 7648 33033 Error Ship option 'Std UK-ROW' is invalid.
20 25636 33033 Error Ship option 'Exp UK Domestic' is invalid.
20 25636 33033 Error Ship option 'Std UK Domestic' is invalid.
20 25636 33033 Error Ship option 'Std UK Europe' is invalid.
20 25636 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
20 25636 33033 Error Ship option 'Std UK-ROW' is invalid.
21 25657 33033 Error Ship option 'Exp UK Domestic' is invalid.
21 25657 33033 Error Ship option 'Std UK Domestic' is invalid.
21 25657 33033 Error Ship option 'Std UK Europe' is invalid.
21 25657 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
21 25657 33033 Error Ship option 'Std UK-ROW' is invalid.
22 25658 33033 Error Ship option 'Exp UK Domestic' is invalid.
22 25658 33033 Error Ship option 'Std UK Domestic' is invalid.
22 25658 33033 Error Ship option 'Std UK Europe' is invalid.
22 25658 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
22 25658 33033 Error Ship option 'Std UK-ROW' is invalid.
23 25666 33033 Error Ship option 'Exp UK Domestic' is invalid.
23 25666 33033 Error Ship option 'Std UK Domestic' is invalid.
23 25666 33033 Error Ship option 'Std UK Europe' is invalid.
23 25666 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
23 25666 33033 Error Ship option 'Std UK-ROW' is invalid.
24 26324 33033 Error Ship option 'Exp UK Domestic' is invalid.
24 26324 33033 Error Ship option 'Std UK Domestic' is invalid.
24 26324 33033 Error Ship option 'Std UK Europe' is invalid.
24 26324 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
24 26324 33033 Error Ship option 'Std UK-ROW' is invalid.
25 29377 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
26 29379 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
27 29380 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
28 29381 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
29 29382 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
3 11544 8058 Error The following attributes are missing for SKU: [11544]: '[manufacturer]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
30 29383 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
31 29384 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
32 29385 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
33 29387 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
34 29388 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
35 29389 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
36 29390 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
37 32230 8567 Error SKU 32230 does not match any ASIN and contains invalid values for attributes required for creation of a new ASIN. New ASIN creation requires the following attributes, for which this SKU provided invalid attribute value(s): merchant_suggested_asin.
37 32230 13013 Error This SKU does not exist in the Amazon.com catalog. Your inventory data was not processed. For reasons why, and help fixing this, see http://sellercentral.amazon.co.uk/gp/errorcode/13013
38 37048 8058 Error The following attributes are missing for SKU: [37048]: '[manufacturer]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
39 37927 33033 Error Ship option 'Exp UK Domestic' is invalid.
39 37927 33033 Error Ship option 'Std UK Domestic' is invalid.
39 37927 33033 Error Ship option 'Std UK Europe' is invalid.
39 37927 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
39 37927 33033 Error Ship option 'Std UK-ROW' is invalid.
4 12144 8005 Error You are attempting to change an identity attribute for this SKU. To proceed, please delete this SKU and recreate the SKU with the appropriate identity attribute. For more information and detailed instructions, see: http://sellercentral.amazon.co.uk/gp/help/23191
4 12144 13013 Error This SKU does not exist in your Amazon inventory so we could not process this record. To correct this error for future feeds, add the SKU to your Amazon account. For more information, see http://sellercentral.amazon.co.uk/gp/errorcode/13013.
4 12144 33033 Error Ship option 'Exp UK Domestic' is invalid.
4 12144 33033 Error Ship option 'Std UK Domestic' is invalid.
4 12144 33033 Error Ship option 'Std UK Europe' is invalid.
4 12144 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
4 12144 33033 Error Ship option 'Std UK-ROW' is invalid.
40 39949 8058 Error The following attributes are missing for SKU: [39949]: '[item_name]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
41 41208 8058 Error The following attributes are missing for SKU: [41208]: '[item_name]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
42 41944 8058 Error The following attributes are missing for SKU: [41944]: '[item_name]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
43 42006 8058 Error The following attributes are missing for SKU: [42006]: '[item_name]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
44 45015 33033 Error Ship option 'Exp UK Domestic' is invalid.
44 45015 33033 Error Ship option 'Std UK Domestic' is invalid.
44 45015 33033 Error Ship option 'Std UK Europe' is invalid.
44 45015 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
44 45015 33033 Error Ship option 'Std UK-ROW' is invalid.
45 49224 8058 Error The following attributes are missing for SKU: [49224]: '[manufacturer]'.For more details, see http://sellercentral.amazon.co.uk/gp/errorcode/8058
46 71765 33033 Error Ship option 'Exp UK Domestic' is invalid.
46 71765 33033 Error Ship option 'Std UK Domestic' is invalid.
46 71765 33033 Error Ship option 'Std UK Europe' is invalid.
46 71765 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
46 71765 33033 Error Ship option 'Std UK-ROW' is invalid.
5 13099 90202 Error There is a restriction in effect at the item level (because of Item-Level gatings on an offer)
6 20700 33033 Error Ship option 'Exp UK Domestic' is invalid.
6 20700 33033 Error Ship option 'Std UK Domestic' is invalid.
6 20700 33033 Error Ship option 'Std UK Europe' is invalid.
6 20700 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
6 20700 33033 Error Ship option 'Std UK-ROW' is invalid.
7 20931 33033 Error Ship option 'Exp UK Domestic' is invalid.
7 20931 33033 Error Ship option 'Std UK Domestic' is invalid.
7 20931 33033 Error Ship option 'Std UK Europe' is invalid.
7 20931 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
7 20931 33033 Error Ship option 'Std UK-ROW' is invalid.
8 20932 33033 Error Ship option 'Exp UK Domestic' is invalid.
8 20932 33033 Error Ship option 'Std UK Domestic' is invalid.
8 20932 33033 Error Ship option 'Std UK Europe' is invalid.
8 20932 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
8 20932 33033 Error Ship option 'Std UK-ROW' is invalid.
9 20934 33033 Error Ship option 'Exp UK Domestic' is invalid.
9 20934 33033 Error Ship option 'Std UK Domestic' is invalid.
9 20934 33033 Error Ship option 'Std UK Europe' is invalid.
9 20934 33033 Error Ship option 'Std UK NorthAmerica' is invalid.
9 20934 33033 Error Ship option 'Std UK-ROW' is invalid.
Here is a screenshot from our seller central showing our shipping options. Not sure if this is relevant or not.
I hope you can help.
Thanks in advance.
Luke
Please use the new shipping template name you have created in the field
merchant-shipping-group-name
i.e use Amazon Shipping
and please note that as per the new shipping settings the shipping override will not work. You have to create an extra shipping template to achieve the same. Amazon allows up to 20 templates
Related
I have a dataframe with multiple columns and 700+ rows and a series of 27 rows. I want to create a new column i.e. series in dataframe as per matching indexes with predefined column in df
data frame I have and need to add series which contains the same indexes of "Reason for absence"
ID Reason for absence Month of absence Day of the week Seasons
0 11 26 7 3 1
1 36 0 7 3 1
2 3 23 7 4 1
3 7 7 7 5 1
4 11 23 7 5 1
5 3 23 7 6 1
6 10 22 7 6 1
7 20 23 7 6 1
8 14 19 7 2 1
9 1 22 7 2 1
10 20 1 7 2 1
11 20 1 7 3 1
12 20 11 7 4 1
13 3 11 7 4 1
14 3 23 7 4 1
15 24 14 7 6 1
16 3 23 7 6 1
17 3 21 7 2 1
18 6 11 7 5 1
19 33 23 8 4 1
20 18 10 8 4 1
21 3 11 8 2 1
22 10 13 8 2 1
23 20 28 8 6 1
24 11 18 8 2 1
25 10 25 8 2 1
26 11 23 8 3 1
27 30 28 8 4 1
28 11 18 8 4 1
29 3 23 8 6 1
30 3 18 8 2 1
31 2 18 8 5 1
32 1 23 8 5 1
33 2 18 8 2 1
34 3 23 8 2 1
35 10 23 8 2 1
36 11 24 8 3 1
37 19 11 8 5 1
38 2 28 8 6 1
39 20 23 8 6 1
40 27 23 9 3 1
41 34 23 9 2 1
42 3 23 9 3 1
43 5 19 9 3 1
44 14 23 9 4 1
this is series table s_conditions
0 Not absent
1 Infectious and parasitic diseases
2 Neoplasms
3 Diseases of the blood
4 Endocrine, nutritional and metabolic diseases
5 Mental and behavioural disorders
6 Diseases of the nervous system
7 Diseases of the eye
8 Diseases of the ear
9 Diseases of the circulatory system
10 Diseases of the respiratory system
11 Diseases of the digestive system
12 Diseases of the skin
13 Diseases of the musculoskeletal system
14 Diseases of the genitourinary system
15 Pregnancy and childbirth
16 Conditions from perinatal period
17 Congenital malformations
18 Symptoms not elsewhere classified
19 Injury
20 External causes
21 Factors influencing health status
22 Patient follow-up
23 Medical consultation
24 Blood donation
25 Laboratory examination
26 Unjustified absence
27 Physiotherapy
28 Dental consultation
dtype: object
I tried this
df1.insert(loc=0, column="Reason_for_absence", value=s_conditons)
out- this is wrong because i need the reason_for_absence colum according to the index of reason for absence and s_conditions
Reason_for_absence ID Reason for absence \
0 Not absent 11 26
1 Infectious and parasitic diseases 36 0
2 Neoplasms 3 23
3 Diseases of the blood 7 7
4 Endocrine, nutritional and metabolic diseases 11 23
5 Mental and behavioural disorders 3 23
6 Diseases of the nervous system 10 22
7 Diseases of the eye 20 23
8 Diseases of the ear 14 19
9 Diseases of the circulatory system 1 22
10 Diseases of the respiratory system 20 1
11 Diseases of the digestive system 20 1
12 Diseases of the skin 20 11
13 Diseases of the musculoskeletal system 3 11
14 Diseases of the genitourinary system 3 23
15 Pregnancy and childbirth 24 14
16 Conditions from perinatal period 3 23
17 Congenital malformations 3 21
18 Symptoms not elsewhere classified 6 11
19 Injury 33 23
20 External causes 18 10
21 Factors influencing health status 3 11
22 Patient follow-up 10 13
23 Medical consultation 20 28
24 Blood donation 11 18
25 Laboratory examination 10 25
26 Unjustified absence 11 23
27 Physiotherapy 30 28
28 Dental consultation 11 18
29 NaN 3 23
30 NaN 3 18
31 NaN 2 18
32 NaN 1 23
i am getting output upto 28 rows and NaN values after that. Instead, I need correct order of series according to indexes for all the rows
While this question is a bit confusing, it seems the desire is to match the series index with the dataframe "Reason for Absence" column. If this is correct, below is a small example of how to accomplish. Keep in mind, the resulting dataframe will be sorted based on the 'Reason for Absence Numerical' column. If my understanding is incorrect, please clarify this question so we can better assist you.
d = {'ID': [11,36,3], 'Reason for Absence Numerical': [3,2,1], 'Day of the Week': [4,2,6]}
dataframe = pd.DataFrame(data=d)
s = {0: 'Not absent', 1:'Neoplasms', 2:'Injury', 3:'Diseases of the eye'}
disease_series = pd.Series(data=s)
def add_series_to_df(df, series, index_val):
df_filtered = df[df['Reason for Absence Numerical'] == index_val].copy()
series_filtered = series[series.index == index_val]
if not df_filtered.empty:
df_filtered['Reason for Absence Text'] = series_filtered.item()
return df_filtered
x = [add_series_to_df(dataframe, disease_series, index_val) for index_val in range(len(disease_series.index))]
new_df = pd.concat(x)
print(new_df)
I need only those company name with year and estimate grp size those are present in all three year eg 2019, 2020, 2021
year Company/Account Name EstimatedGroupSize
0 2019 Unknown 19550
1 2019 Mayo Clinic 7754
2 2019 Deloitte 6432
3 2019 Rizona State 5582
4 2019 Intel Corporation 4595
5 2020 Deloitte 4063
6 2020 Unknown 3490
7 2021 Unknown 3484
8 2020 Intel Corporation 3460
9 2021 Intel Corporation 3433
10 2021 Deloitte 3250
So my output should be
year Company/Account Name EstimatedGroupSize
0 2019 Unknown 19550
2 2019 Deloitte 6432
4 2019 Intel Corporation 4595
5 2020 Deloitte 4063
6 2020 Unknown 3490
7 2021 Unknown 3484
8 2020 Intel Corporation 3460
9 2021 Intel Corporation 3433
10 2021 Deloitte 3250
Here is solution for filter year with Company/Account Name if present at least one row and filter original DataFrame by inner merge:
#if need filter ony some years first
df = df[df['year'].isin([2019, 2020, 2021])]
df1 = pd.crosstab(df['year'], df['Company/Account Name'])
df = df.merge(df1.loc[:, df1.gt(0).all()].stack().index.to_frame(index=False))
print (df)
year Company/Account Name EstimatedGroupSize
0 2019 Unknown 19550
1 2019 Deloitte 6432
2 2019 Intel Corporation 4595
3 2020 Deloitte 4063
4 2020 Unknown 3490
5 2021 Unknown 3484
6 2020 Intel Corporation 3460
7 2021 Intel Corporation 3433
8 2021 Deloitte 3250
IIUC,
years = [2019, 2020, 2021]
new_df = \
df.loc[pd.get_dummies(df['year'])
.groupby(df['Company/Account Name'])[years]
.transform('sum')
.gt(0)
.all(axis=1)]
print(new_df)
year Company/Account Name EstimatedGroupSize
0 2019 Unknown 19550
2 2019 Deloitte 6432
4 2019 Intel-Corporation 4595
5 2020 Deloitte 4063
6 2020 Unknown 3490
7 2021 Unknown 3484
8 2020 Intel-Corporation 3460
9 2021 Intel-Corporation 3433
10 2021 Deloitte 3250
Or:
years = [2019, 2020, 2021]
new_df = \
df.groupby('Company/Account Name')\
.filter(lambda x: np.isin(years, x['year']).all())
I am trying to get the result column to be the sum of the value column for all rows in the data frame where the country is equal to the country in that row, and the date is on or before the date in that row.
Date Country ValueResult
01/01/2019 France 10 10
03/01/2019 England 9 9
03/01/2019 Germany 7 7
22/01/2019 Italy 2 2
07/02/2019 Germany 10 17
17/02/2019 England 6 15
25/02/2019 England 5 20
07/03/2019 France 3 13
17/03/2019 England 3 23
27/03/2019 Germany 3 20
15/04/2019 France 6 19
04/05/2019 England 3 26
07/05/2019 Germany 5 25
21/05/2019 Italy 5 7
05/06/2019 Germany 8 33
21/06/2019 England 3 29
24/06/2019 England 7 36
14/07/2019 France 1 20
16/07/2019 England 5 41
30/07/2019 Germany 6 39
18/08/2019 France 6 26
04/09/2019 England 3 44
08/09/2019 Germany 9 48
15/09/2019 Italy 7 14
05/10/2019 Germany 2 50
I have tried the below code but it sums up the entire column
df['result'] = df.loc[(df['Country'] == df['Country']) & (df['Date'] >= df['Date']), 'Value'].sum()
as your dates are ordered you could do:
df['Result'] = df.grouby('Coutry').Value.cumsum()
id name age year
0 khu 12 2018
1 she 21 2019
2 waqar 22 2015
3 khu 12 2018
4 she 21 2018
5 waqar 22 2015
want like this
id name age year
0 khu 12 2018
1 she 21 2019
2 waqar 22 2015
0 khu 12 2018
1 she 21 2018
2 waqar 22 2015
Use GroupBy.ngroup:
df['id'] = df.groupby('name', sort=False).ngroup()
#if need grouping by multiple columns for check duplicates
#df['id'] = df.groupby(['name','age'], sort=False).ngroup()
print (df)
id name age year
0 0 khu 12 2018
1 1 she 21 2019
2 2 waqar 22 2015
3 0 khu 12 2018
4 1 she 21 2018
5 2 waqar 22 2015
Using factorize as well you can check with category and cat.codes, or sklearn LabelEncoder
df['id']=pd.factorize(df['name'])[0]
df
Out[470]:
id name age year
0 0 khu 12 2018
1 1 she 21 2019
2 2 waqar 22 2015
3 0 khu 12 2018
4 1 she 21 2018
5 2 waqar 22 2015
i have a big df, this is a example to ilustrate my issue. I want to know from this dataframe whichs id by year_of_life are in the first percent in terms of jobs. I want to identify (i am thinking with a dummy) the one percent by years_of_life which has more jobs from the distribution.
for example
id year rap jobs_c jobs year_of_life rap_new
1 2009 0 300 10 NaN 0
2 2012 0 2012 12 0 0
3 2013 0 2012 12 1 1
4 2014 0 2012 13 2 1
5 2015 1 2012 15 3 1
6 2016 0 2012 17 4 0
7 2017 0 2012 19 5 0
8 2009 0 2009 15 0 1
9 2010 0 2009 2 1 1
10 2011 0 2009 3 2 1
11 2012 1 2009 3 3 0
12 2013 0 2009 15 4 0
13 2014 0 2009 12 5 0
14 2015 0 2009 13 6 0
15 2016 0 2009 13 7 0
16 2011 0 2009 3 2 1
17 2012 1 2009 3 3 0
18 2013 0 2009 18 4 0
19 2014 0 2009 12 5 0
20 2015 0 2009 13 6 0
.....
100 2009 0 2007 5 6 1
I want to identify (i am thinking with a dummy) the one percent by years_of_life which has more jobs from the distribution and then sum the jobs from those ids by year_of_life in the first percent
i try something like thi:
df.groupby(['year_of_life']).filter(lambda x : x.jobs>
x.jobs.quantile(.99))['jobs'].sum()
but i have the following error
TypeError: filter function returned a Series, but expected a scalar bool
Is this what you need ?
df.loc[df.groupby(['year_of_life']).jobs.apply(lambda x : x>x.quantile(.99)).fillna(True),'jobs'].sum()
Out[193]: 102