0

i like to import a dataset with pandas, this is my code:

data = pd.read_csv(source + 'clustering_CB\\AAA_tableau_jan_oct_19_cardiologia.txt' ,sep='\t' , engine='python')

Column Col10 contains string values which let me know the duration of a web visit, here's an example

00:02:35

2 minute and 35 seconds. What i like to do is to import this columns as a time format in order to measure (in seconds or in minutes) the duration of the web visit.

1
  • use pd.to_timedelta. Commented Oct 29, 2019 at 9:59

1 Answer 1

1

If I understand your question correctly, the column already contains timedelta values (in string format) - in this case, you can apply the pd.to_timedelta function to the column:

timedelta = pd.to_timedelta(df["Col10"])
Sign up to request clarification or add additional context in comments.

2 Comments

yess, thank you but i was guessing if this could be possible while importing data
@lucapellerossapelles I think you can, using the converters keyword in the read_csv function call. I've never used it myself, but I think it should be able to do this as well. You can read more in the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.