#๐Ÿ”’ Help with Linear Regression Model

41 messages ยท Page 1 of 1 (latest)

stark belfryBOT
#

@cyan forge

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.

knotty remnant
#

!code; also please send the error message

stark belfryBOT
#
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.

deft nymph
#

Can you send the exact error, too?

cyan forge
#

Thats the error message

knotty remnant
#

that means it can't find a column named Fecha nor Saldo in the dataframe, line 9

#

can you print a df.head() just before line 9?

cyan forge
#

Ok let me try it

cyan forge
#

df.head()

#

line 10, in <module>
columnasseleccionadas = df[["Client", "Fecha", "Saldo"]] line 4108, in _getitem
indexer = self.columns._get_indexer_strict(key, "columns")[1]line 6200, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)line 6252, in _raise_if_missing
raise KeyError(f"{not_found} not in index")
KeyError: "['Fecha', 'Saldo'] not in index"

knotty remnant
#

you also deleted the original code you posted so I'm not sure how I'm supposed to help now

cyan forge
#

import pandas as pd
from sklearn.linear_model import LinearRegression

archivo_excel=
df=pd.read_excel(archivo_excel)
df = df.replace('&', '', regex=True)
s="&"
s = s.replace("&", "")
df.head()
columnas_seleccionadas = df[["Client", "Fecha", "Saldo"]]
print(columnas_seleccionadas.head(n=1048576))
df_filtrado = df[df["Client", "Fecha", "Saldo"].apply(lambda row: row.str.contains('texto').any(), axis=1)]
x=df_filtrado["Fecha"].values.reshape(-1,1)
y = df_filtrado["Saldo"].values
model = LinearRegression()
model.fit(x, y)
intercepto = model.intercept_
pendiente = model.coef_
print("Intercepto: ", intercepto)
print("Pendiente: ", pendiente)
resultados = pd.DataFrame({'Intercepto': [intercepto], 'Pendiente': [pendiente]})
resultados.to_excel(r"

#

Here its the code

#

sorry for the incovenience

knotty remnant
#

then after we see what's wrong, we can debug

#

no

#

print(df.head())

#

like write actual code to print df.head()
then show the output in the console

cyan forge
#

Ok its charging

#

In the Output and debug console it does not appear anything

#

line 6252, in _raise_if_missing
raise KeyError(f"{not_found} not in index")
KeyError: "['Fecha', 'Saldo'] not in index"

knotty remnant
cyan forge
#

This is what it appears . i Cannot send the link of the doc since its confidential but thanks

knotty remnant
#

there should be stuff above that, if you did add the print

cyan forge
#

Yeah there is more

knotty remnant
#

and it should look like the first 5 rows of the dataframe (along with the columns)
show that

#

or is that also confidential so you can't show it

cyan forge
#

Give me a sec

knotty remnant
#

just look at the columns then, the error says that 'Fecha' and 'Saldo' isn't one of the columns

cyan forge
#

But in my excel files they are there

#

They are columns

knotty remnant
#

so something went wrong, and noone can tell what went wrong if you don't show what the dataframe looks like right now

#

specifically the columns

cyan forge
#

Thank you for your help

#

The first five columns it appears but it stills says the same issue

stark belfryBOT
#
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.

#

๐Ÿ”’ Help with Linear Regression Model