#๐ Help with Linear Regression Model
41 messages ยท Page 1 of 1 (latest)
@cyan forge
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.
!code; also please send the error message
Can you send the exact error, too?
Thats the error message
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?
Ok let me try it
I wrote df.head and it stills appears the same
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"
yeah I'm asking what it prints
can't tell what went wrong if you can't see what's going on
you also deleted the original code you posted so I'm not sure how I'm supposed to help now
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
df.head()
I meant todf.head()and show what it prints on the console
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
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"
in TERMINAL?
This is what it appears . i Cannot send the link of the doc since its confidential but thanks
there should be stuff above that, if you did add the print
Yeah there is more
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
Give me a sec
just look at the columns then, the error says that 'Fecha' and 'Saldo' isn't one of the columns
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
Thank you for your help
The first five columns it appears but it stills says the same issue
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