Question: I'm trying to create a dataframe using 1 list and 1 dictionary.

The first column is the word (equal to the list), the second the count (some words are in the dictionary with the correspondent count).

Example:

```
list = ['hi', 'hello', 'bye']
dict = {'hi': 10}

df = hi    10
     hello 0
     bye   0

```

What I want to do is do it using one list comp, something like:

```
df = pd.DataFrame([[word, count] for word in list if word in dict.keys(): count = dict[word] else: count = 0 ], columns=['words', 'count'])

```

Answer: 
You can either mangle the strings and cast to integer directly (more efficient) or convert to datetime, format to string and cast to integer (maybe more convenient / readable).

Ex:

```
import pandas as pd
# dummy data:
df = pd.DataFrame({'date': ['10/11/2012', '11/12/2013']}) # mm/dd/yyyy
# working with strings...
tmp = df['date'].str.split('/')
df['date_int'] = (tmp.str[2]+tmp.str[0]+tmp.str[1]).astype(int)
# working with datetime...
df['date_int'] = pd.to_datetime(df['date']).dt.strftime('%Y%m%d').astype(int)

```

output in both cases:

```
0    20121011
1    20131112
Name: date_int, dtype: int32

```
You can sum year \* 1000 + month \* 100 + day:

```
df = pd.DataFrame({'dt': pd.date_range('2021-01-01', '2021-01-05')})
df['dt_int'] = df['dt'].dt.year * 1000 + df['dt'].dt.month * 100 + df['dt'].dt.day

df

```

Output:

```
          dt   dt_int
0 2021-01-01  2021101
1 2021-01-02  2021102
2 2021-01-03  2021103
3 2021-01-04  2021104
4 2021-01-05  2021105

```

---

**Update**

If column values are strings with a known format `mm/dd/yyyy`, you can concatenate the substrings and convert to integer:

```
df = pd.DataFrame({'dt': ['10/11/2012', '11/12/2013']})
df['dt_int'] = (
    df['dt'].str[6:] +
    df['dt'].str[0:2] +
    df['dt'].str[3:5]).astype(int)

```

This can save some time compared to the version with `split`:

```
%%time
df['dt_int'] = (
    df['dt'].str[6:] +
    df['dt'].str[3:5] +
    df['dt'].str[0:2]).astype(int)

CPU times: user 7.08 ms, sys: 646 µs, total: 7.72 ms
Wall time: 6.95 ms

```

```
%%time
tmp = df['dt'].str.split('/')
df['dt_int'] = (tmp.str[2]+tmp.str[0]+tmp.str[1]).astype(int)

CPU times: user 16.5 ms, sys: 0 ns, total: 16.5 ms
Wall time: 15.5 ms

```