Python Forum
change item in column based on the item before[solved]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change item in column based on the item before[solved]
#2
Your code can be greatly simplified.
The following opens the input spreadsheet you supplied, and writes it back out as a csv.
It does nothing to modify the data, you will have to add that.
The print statement only shows what was read and should be removed when statisfied
import os
import pandas as pd

# make sure starting directory set
os.chdir(os.path.abspath(os.path.dirname(__file__)))
n = 2
df = pd.read_excel("newfile1.xlsx", dtype=str)
print(df)
pd.to_csv('newfile2.csv')
Output:
datetime,intensity 0 19790111-1007,3.333 1 19790111-1007,3.333 2 19790111-1007,3.333 3 19790111-1007,0.556 4 19790111-1007,0.556 5 19790111-1007,0.556 6 19790111-1007,0.556 7 19790111-1007,0.556 8 19790111-1007,0.556 9 19790111-1007,3.333 10 19790111-1007,0.370 11 19790111-1007,0.370 12 19790111-1007,0.370 13 19790111-1007,0.370 14 19790111-1007,0.370 15 19790111-1007,0.370 16 19790111-1007,0.370 17 19790111-1007,0.370 18 19790111-1007,0.370 19 19790111-1007,0.476 20 19790111-1007,0.476 21 19790111-1007,0.476 22 19790111-1007,0.476 23 19790111-1007,0.476 24 19790111-1007,0.476 25 19790111-1007,0.476
Reply


Messages In This Thread
RE: change item in column based on the item before - by Larz60+ - Jan-10-2022, 12:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  removing item pastakipp 3 1,973 Oct-25-2020, 09:15 PM
Last Post: deanhystad
  Python Adding +1 to a list item cointained in a dict ElReyZero 1 2,136 Apr-30-2020, 05:12 AM
Last Post: deanhystad
  need help removing an item from a list jhenry 4 4,279 Oct-13-2017, 08:15 AM
Last Post: buran
  Determine if a list contains a specific number of an item flannel_man 3 5,009 Nov-12-2016, 04:46 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020