r/dataanalysis • u/vich_lasagna • Aug 05 '23
How can I fix this?
I have created a dataframe called semi_df in previous cells. but when I close and open the same python file in my jupyter notebook the cells below cannot read the data frames in the cells above them i have to go to the cells and hit shift +enter again and again so that the cells below can read the code above them...
31
u/DoctorFuu Aug 05 '23
Have you tried defining semi_df?
(I see a [1] which could indicate that this is the first cell you've run in this session, if semi_df was defined in another cell you need to run it first)
2
u/data-lite Aug 07 '23
This.
2
u/Anti-ThisBot-IB Aug 07 '23
Hey there data-lite! If you agree with someone else's comment, please leave an upvote instead of commenting "This."! By upvoting instead, the original comment will be pushed to the top and be more visible to others, which is even better! Thanks! :)
I am a bot! If you have any feedback, please send me a message! More info: Reddiquette
5
Aug 05 '23 edited Aug 06 '23
An easy makeshift - if you don't want to run all the previous cells and redo all operations - is to simply save your dataframe and reload when you start again.
semi_df.to_csv("semi_df.csv")
Then you just pick up again loading your frame with semi_df = pd.read_csv("semi_df.csv").
This will save you from running everything again and you are right there where you left of.
Alternatively you can pickle all data too. I usually save all important data and variables in a pickle dict.
5
u/CaptainFoyle Aug 05 '23
Did you run the previous cells? Otherwise, it's probably a spelling mistake.