How to check conditions in each row in data frame and push the data accordinly into excel and run marco

﹥>﹥吖頭↗ 提交于 2020-04-30 06:28:19

问题


df=pd.DataFrame({'0':["abc-dsa","abc-xyz","abt-cab","xyz-0vc"],'1':['axc-0aa',"abd-xyz","abt-Rac","xyz-1avc"],'3':['bcd-aaa',"NaN","bcd-9ac","xyy-9vc"]})

I have this Data Frame, I want to push it into excel and run a macro.

First condition is IF first three characters are same in row then they will be stored in single column

second condition is IF they the first three characters are not same they will be saved in same row.

chain of operation is.

  1. read data frame

  2. check conditions and store data accordingly for first row

  3. run a macro and wait for 1 min

  4. read data frame (second row in dataframe).check conditions and store it again in excel run macro

EXAMPLE:

first row in dataframe has abc-dsa, abc-xyz, abt-cab, xyz-0vc.

In this we have two sets of data that are identical for first three characters i.e. abc so these will be stored in column A1 in excel rest do not match and hence will be stored in B1 and C1 respectively.

in excel

A1

abc-dsa

abc-xyz

B1

abt-cab

c1

xyz-0vc

I just want to know if it is possible to check each row values and store it in excel or not.

来源:https://stackoverflow.com/questions/61450810/how-to-check-conditions-in-each-row-in-data-frame-and-push-the-data-accordinly-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!