Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 212301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:10:27+00:00 2026-05-11T18:10:27+00:00

I have a CSV file with several entries, and each entry has 2 unix

  • 0

I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates.

I have a method called convert(), which takes in the timestamp and converts it to YYYYMMDD.

Now, since I have 2 timestamps in each line, how would I replace each one with the new value?

EDIT: Just to clarify, I would like to convert each occurrence of the timestamp into the YYYYMMDD format. This is what is bugging me, as re.findall() returns a list.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:10:27+00:00Added an answer on May 11, 2026 at 6:10 pm

    I assume that by “unix timestamp formatted date” you mean a number of seconds since the epoch. This assumes that every number in the file is a UNIX timestamp. If that isn’t the case you’ll need to adjust the regex:

    import re, sys
    
    # your convert function goes here
    
    regex = re.compile(r'(\d+)')
    for line in sys.stdin:
      sys.stdout.write(regex.sub(lambda m:
      convert(int(m.group(1))), line))
    

    This reads from stdin and calls convert on each number found.

    The “trick” here is that re.sub can take a function that transforms from a match object into a string. I’m assuming your convert function expects an int and returns a string, so I’ve used a lambda as an adapter function to grab the first group of the match, convert it to an int, and then pass that resulting int to convert.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file which contains an ID and several other columns. I
I have a dump of several Postgresql Tables in a selfcontained CSV file which
I have a .csv file that is frequently updated (about 20 to 30 times
I have a CSV file that holds about 200,000 - 300,000 records. Most of
I have a csv file of the format: 270291014011 ED HARDY - TRUE TO
I have my CSV file imported as such: records = FasterCSV.read(path, :headers => true,
I have a large CSV file and I want to execute a stored procedure
I have a CSV data file with rows that may have lots of columns
I have a CSV of file of data that I can load in R
I have an application that reads a CSV file with piles of data rows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.