0

It's really weird but I have tried all the solutions shared here so sharing my main code.

first_df = pd.read_csv(f'C:\\Users\\y\\AlgoTrading\\Algo Live\\Final\\stockpicks\\yy.txt', sep=",",names=['ticker','entry2','entry3','entry4'])
first_df.set_index('ticker',inplace=True)
first_df

Now when I update using the below code and it works fine.

first_df.loc["stock"].entry2 = False

No errors, but when I read 5 columns

first_df = pd.read_csv(f'C:\\Users\\y\\AlgoTrading\\Algo Live\\Final\\stockpicks\\yy.txt', sep=",",names=['ticker','entry2','entry3','entry4','entry5'])
first_df.set_index('ticker',inplace=True)
first_df

Now when I update using the below code and it throws error and doesn't update anything in the dataframe.

first_df.loc["stock"].entry2 = False

this is how the file looks

When 4 - OIL,False,True,True When 5 - SHYAMMETL,True,True,True,2022-12-21 09:55:13.137608

Any help please?

I have tried all the methods I could find, including creating copy and such.

whatayush
  • 11
  • 2
  • Use `first_df.loc["stock", "entry2"]` – mozway Dec 21 '22 at 06:23
  • That worked! Checking in live if it does too, but why did this work? Specially what difference does it make between 4 columns and 5? – whatayush Dec 21 '22 at 06:35
  • Have you read the duplicate link? ;) No matter the difference, you can't always predict when slicing will generate a copy, do always slice correctly. – mozway Dec 21 '22 at 06:36

0 Answers0