How do i get datetime into a tableau extract with pantab

0 votes

0

I have this code:

import pantab
import pandas as pd
import datetime
df = pd.DataFrame([
    [datetime.date(2018,2,20), 4],
    [datetime.date(2018,2,20), 4],
], columns=["date", "num_of_legs"])

pantab.frame_to_hyper(df, "example.hyper", table="animals")

which is causing this error:

TypeError: Invalid value "datetime.date(2018, 2, 20)" found (row 0 column 0)

How can I fix this?

Mar 10, 2022 in Tableau by Neha
• 9,020 points
1,174 views

1 answer to this question.

0 votes

Panda dtypes handle dates and strings as objects, thus you must know which columns are datetime columns. There's a universe where data scientists don't give a damn about dates, but evidently not mine. Anyway, here's the workaround till Pandas implements the date dtype:

[https://github.com/innobi/pantab/issues/100][1]

And just to reduce it down to do what I did:

def createHyper(xlsx, filename, tablename):
    for name in xlsx.columns:
        if 'date' in name.lower():
            xlsx[name] = pd.to_datetime(xlsx[name],errors='coerce',utc=True)
    pantab.frame_to_hyper(xlsx,filename,table=tablename)
    return open(filename, 'rb')

errors = 'coerce' makes it so you can have dates like 1/1/3000 which is handy in a world of scd2 tables utc = True was necessary for me because my dates were timezone sensitive, yours may not be.

answered Mar 14, 2022 by Vaani
• 7,070 points

Related Questions In Tableau

0 votes
1 answer

How to get multiple Sets of Measure Names with different Filters on a single sheet in Tableau?

The easiest solution to your query is: 1) ...READ MORE

answered Aug 23, 2018 in Tableau by Naruto
• 710 points
15,342 views
0 votes
1 answer

How do I add a custom login and logout page in my Tableau Server on-prem?

I don't believe it is "officially" possible ...READ MORE

answered Mar 4, 2022 in Tableau by Neha
• 9,020 points
746 views
0 votes
1 answer

How can I convert a dimension into a measure in Tableau

I'd like to ask a technical question ...READ MORE

answered Apr 5, 2022 in Tableau by Neha
• 9,020 points
1,237 views
0 votes
1 answer

How to share a workbook with client in Tableau who do not have Tableau account or tableau reader

It's possible that there isn't a way ...READ MORE

answered Apr 5, 2022 in Tableau by Neha
• 9,020 points
659 views
0 votes
0 answers

Using Python and Tableau in conjunction with one another

Is it possible to mix Python visualisations ...READ MORE

Feb 28, 2022 in Tableau by Vaani
• 7,070 points
516 views
0 votes
0 answers

Tableau Desktop Inside Tableau Server

Is there an executable for Tableau Desktop ...READ MORE

Feb 28, 2022 in Tableau by Vaani
• 7,070 points
463 views
0 votes
0 answers

Tableau Map view Continent List

I've been attempting to tidy up my ...READ MORE

Feb 28, 2022 in Tableau by Vaani
• 7,070 points
581 views
0 votes
0 answers

Downloading tableau workbook from tableau server with data

I'm brand new to tableau server. I ...READ MORE

Feb 28, 2022 in Tableau by Vaani
• 7,070 points
591 views
0 votes
1 answer

Tableau: How to create a filter based of 3 different columns?

The case you're using for filters is ...READ MORE

answered Mar 16, 2022 in Tableau by Vaani
• 7,070 points
2,816 views
0 votes
1 answer

combine two data sets in tableau so that I can show a forecast for the next 3 months

I believe the best approach is to ...READ MORE

answered Apr 5, 2022 in Tableau by Vaani
• 7,070 points
905 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP