将简单的Excel函数转换为Pandas DF
我是Python的初学者,我尝试将Excel表转换为Pandas DataFrame。
我在Excel中有以下if语句: = if(mod(f183,2)= 1,“暂停”,“ break”)
列F183代表8个季度:1,2,3,4,5,6,7,8
我开始定义一个函数,然后用.Apply将其放入DataFrame中,但我很努力地首先设置该功能。这就是我到目前为止的:
def pause(i):
i = df['Quarter']
if i.mod(2) == 1:
return "PAUSE"
else:
return "BREAK"
当我用例如暂停(2)调用该功能时,我会遇到一个值错误。
谢谢您的建议
I'm quite a beginner in python and I try to convert an excel sheet into a pandas dataframe.
I have following if statement in excel:
=IF(MOD(F183,2)=1, "PAUSE", "BREAK")
The column F183 represents 8 quarters: 1,2,3,4,5,6,7,8
I started to define a function and then to put it into the dataframe with .apply, but I'm quite struggling with setting up the function in the first place. That's what I have so far:
def pause(i):
i = df['Quarter']
if i.mod(2) == 1:
return "PAUSE"
else:
return "BREAK"
When I call the function with e.g. pause(2), I get a value error.
Thank you for any suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以 - 在您的电子表格中的f列在DF ['Quarter']
编辑中表示:我会稍微编辑该函数以仅处理值,然后应用“映射”,以将功能映射到系列DF的每个元素[ [季度']
edit2:使用应用功能,我会通过此lambda功能 - 似乎也有效
You could this - where column F in your spreadsheet is represented by df['Quarter']
Edit: I would slightly edit the function to take on values only, then apply 'map' that maps that function to each element of the series df['Quarters']
Edit2: with the apply function, I would pass in this lambda function - seems to work as well