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

  • SEARCH
  • Home
  • 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 9040271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:56:52+00:00 2026-06-16T09:56:52+00:00

I have a csv file which contains date and time stamps as two of

  • 0

I have a csv file which contains date and time stamps as two of the columns. I am using pandas read_csv to read the contents into a dataframe. My ultimate goal is to plot time series graphs from the data.

!head vmstat.csv
wait_proc,sleep_proc,swapped_memory,free_memory,buffered_memory,cached_memory,swapped_in,swapped_out,received_block,sent_block,interrups,context_switches,user_time,sys_time,idle_time,wait_io_time,stolen_time,date,time
0,0,10896,3776872,380028,10284052,0,0,6,16,7716,4755,3,1,96,0,0,2012-11-01,08:59:27
0,0,10896,3776500,380028,10284208,0,0,0,40,7471,4620,0,0,99,0,0,2012-11-01,08:59:32
0,0,10896,3749840,380028,10286864,0,0,339,19,7479,4704,20,2,77,1,0,2012-11-01,08:59:37
0,0,10896,3747536,380028,10286964,0,0,17,118,7488,4638,0,0,99,0,0,2012-11-01,08:59:42
0,0,10896,3747452,380028,10287148,0,0,0,24,7489,4676,0,0,99,0,0,2012-11-01,08:59:47


df = read_csv("vmstat.csv", parse_dates=[['date','time']])
f = DataFrame(df, columns=[ 'date_time',  'user_time', 'sys_time', 'wait_io_time'])

In [3]: f
Out[3]:
date_time               user_time  sys_time     wait_io_time
0  2012-11-01 08:59:27          3         1             0
1  2012-11-01 08:59:32          0         0             0
2  2012-11-01 08:59:37         20         2             1
3  2012-11-01 08:59:42          0         0             0
4  2012-11-01 08:59:47          0         0             0

So far, we could read the data correctly and date_time is combined in the DataFrame. There are issues if I try to used the date_time from df as index. Specifying index = df.date_time gives all NaN values:

dindex = f['date_time']
print dindex
g = DataFrame(f, columns=[ 'user_time', 'sys_time', 'wait_io_time'], index=dindex)

In [7]: g
Out[7]:
0    2012-11-01 08:59:27
1    2012-11-01 08:59:32
2    2012-11-01 08:59:37
3    2012-11-01 08:59:42
4    2012-11-01 08:59:47
Name: date_time  <---- dindex
g:
                 user_time  sys_time  wait_io_time
date_time                                             
2012-11-01 08:59:27        NaN       NaN           NaN
2012-11-01 08:59:32        NaN       NaN           NaN
2012-11-01 08:59:37        NaN       NaN           NaN
2012-11-01 08:59:42        NaN       NaN           NaN
2012-11-01 08:59:47        NaN       NaN           NaN

As you see, the column values are coming out as all NaNs. How do I get correct values as in the intermediate f frame?

  • 1 1 Answer
  • 0 Views
  • 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-06-16T09:56:57+00:00Added an answer on June 16, 2026 at 9:56 am

    You want to use set_index:

    df1 = df.set_index('date_time')
    

    Which selects the column 'date_time' as an index for the new DataFrame.

    .

    Note: The behaviour you are coming across in the DataFrame constructor is demonstrated as follows:

    df = pd.DataFrame([[1,2],[3,4]])
    df1 = pd.DataFrame(df, index=[1,2])
    
    In [3]: df1
    Out[3]: 
        0   1
    1   3   4
    2 NaN NaN
    
    • 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 numbers,date and text. I have to extract
I have a CSV file which contains an ID and several other columns. I
I have a csv file (tab deliminated) which contains 2 columns which looks like
I have a csv file which has two columns, a numeric ID ( IDVAR
I have a Testing project that contains a csv file which a webtest uses
I have .zip file which contain csv data. I am reading .zip file using
I have a CSV file the first row of which contains the variables names
I have a CSV file the first row of which contains the variables names
I have a large CSV file, approx 10 MB in size, which contains all
I have a package which contains a csv file which I put in inst/extdata

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.