Home > OS >  Bokeh Not Assigning A Date?
Bokeh Not Assigning A Date?

Time:08-29

I'm having an issue plotting a timeline using Bokeh. The documentation says that you should be able to reassign the default using '''parse_dates''' but when I create the plot:

example = pd.read_csv(
    "exampledataframe.csv",
    parse_dates=["Date"],
    infer_datetime_format=True,
    index_col=0
);
display_timeline(example) 

I get this error

KeyError: "None of [Index(['TimeGenerated'], dtype='object')] are in the [columns]

Why isn't Bokeh reassigning the index to the "Date" column in my dataframe? I can't find anything about the issue.

Also, please forgive mistakes in terminology. I am a novice in data analysis.

CodePudding user response:

You can use the arguments names and header in pandas.read_csv to rename the Date column :

example = pd.read_csv(
    "exampledataframe.csv",
    parse_dates=["Date"],
    infer_datetime_format=True,
    index_col=0,
    names=["TimeGenerated", "...."],
    header=None
);

display_timeline(example) 

Make sure to assign/add (by order) in names argument the list of the columns names of your .csv.

  • Related