#🔒 panda attribute error

19 messages · Page 1 of 1 (latest)

daring otter
#

hey guys so I've been trying to learn python. Now im trying to calculate something with sympy, but no matter what i do it seems to keep giving me attribute error like such. AttributeError: 'dict' object has no attribute 'evalf'. Any ideas why?
def panda_thing(data, pca):

    header = data[0]
    data = data[1:]
    df = pd.DataFrame(data, columns=header)

    df['Amount'] = df['Amount'].astype(float)
    df['Class'] = df['Class'].astype(int)

    x = sp.symbols('x')
    expr = 2.5 * x**3 + 3 * x**2 + 3.5 * x + 5
    derivative_expr = sp.diff(expr, x)

    normal_amounts = df[df['Class'] == 0]['Amount'].tolist()
    malicious_amounts = df[df['Class'] == 1]['Amount'].tolist()

    normal_derivatives = [float(derivative_expr.subs(x, amt).evalf()) for amt in normal_amounts]
    malicious_derivatives = [float(derivative_expr.subs(x, amt).evalf()) for amt in malicious_amounts]

    Q1 = [normal_derivatives, malicious_derivatives]

    a = sp.symbols('a')
    eq = a * x + 3
    Q2 = [((sp.solve(a * x + 3)[0].evalf()), 1) for pca_val in pca]

    return [Q1, Q2]```
waxen kettleBOT
#

@daring otter

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

halcyon lion
#

!code

waxen kettleBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

halcyon lion
#

that is 99% sympy and does not really have much to do with pandas

#

did you try printing normal_amounts to see if it looks like the list you expected?

daring otter
#

wiat hold up this is sympy

halcyon lion
#

if it does, then debug it with that list, without taking the rest of the function into account

if it doesn't, then debug the process leading up to that list, again ignoring the parts of the function that have nothing to do with the problem itself

daring otter
#

kk thx i'll give that a try

#

also is ther a way to rename this cause its supposed to say sympy

halcyon lion
#

not sure, let me check

#

!help

waxen kettleBOT
#
Command Help

BotSource
!source [source_item]
Display information and a GitHub link to the source code of a command, tag, or cog.

Branding
!branding
Control the branding cog.

DocCog
!docs [symbol_name]
Look up documentation for Python symbols.

Help
!help [command]
Shows help for bot commands

HelpForum
!help-forum close
Make the help post this command was called in dormant.
!help-forum
A group of commands that help manage our help forum system.
!help-forum title <title>
Rename the help post to the provided title.

daring otter
#

sympy attribute error

#

changed it cheers!

daring otter
#

heyo so i fixed the error but the values given are weird

#

its giving me [(-2.27/x, 1), (-2.19/x, 1), (-2.3/x, 1), (-2.07/x, 1), (-2.28/x, 1), (-2.12/x, 1),... etc but supposed to just return one value

waxen kettleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.