0

This is my csv file.

enter image description here

Iam uploading this data to db using python pandas.How to find the number of fee columns are there(fee_1,fee_2,fee_3)?. Because the start,end,fee columns are dynamic. I need to upload based on the number of fee columns.

If number of fee columns is 2 means i need to upload this,

"slot_fee":[{"start": i['Start_1'],"end": i['End_1'],"fee": i['Fee_1']},{"start": i['Start_2'],"end": i['End_2'],"fee": i['Fee_2']}]

If it is 3 means i need to upload this,and so on.

"slot_fee":[{"start": i['Start_1'],"end": i['End_1'],"fee": i['Fee_1']},{"start": i['Start_2'],"end": i['End_2'],"fee": i['Fee_2']},{"start": i['Start_3'],"end": i['End_3']]

Can anyone help me with the python pandas code for this?

1

1 Answer 1

1

If I understand your question correctly this might help :

df.columns[df.columns.str.startswith('Fee_')]

it gives you the list of columns that start with Fee_, if you want the last one you can add

df.columns[df.columns.str.startswith('Fee_')][-1]

Sign up to request clarification or add additional context in comments.

3 Comments

It is giving only this output. Index([], dtype='object')
can you upload an example of the dataframe i can reproduce ? @rovoda
I have added the dataframe above. Need the number of fee columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.