Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas dataframe map

df.applymap(lambda x: x**2)
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

pandas series map

s.map({'cat': 'kitten', 'dog': 'puppy'})
0   kitten
1    puppy
2      NaN
3      NaN
dtype: object
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

Syntax of pandas map()

# Syntax of Series.map()
Series.map(arg, na_action=None)
Comment

map dataframe

>>> s.map({'cat': 'kitten', 'dog': 'puppy'})
0   kitten
1    puppy
2      NaN
3      NaN
dtype: object
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

map column dataframe python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Comment

PREVIOUS NEXT
Code Example
Python :: i want to get only first record of each user in pandas 
Python :: can 2020 get any worse 
Python :: find location of a class in python 
Python :: lines = paths.read().splitlines() 
Python :: hidden semi markov model python from scratch 
Python :: set shortcut for Qaction pyqt5 
Python :: multivariable traces f(x, y) = sin(x)cos(y) 
Python :: ldap python how to print entries 
Python :: numpy index array all except 
Python :: add 10 min to current time django 
Python :: try finally return precedent 
Python :: etails of the Response object by using help() method 
Python :: flask pass an array of dicts 
Python :: Python Raw String to ignore escape sequence 
Python :: Python Decorating Functions with Parameters 
Python :: can we use for loop inside if statement 
Python :: delete to trash 
Python :: NxN Array 
Python :: what is cls and args in python classmethod 
Python :: Python RegEx Split – re.split() Syntax 
Python :: wap in python to print the sum of the series 1 + 1/2! + 1/3! 
Python :: stacked percentage bar chart 
Python :: como colocar uma variavel no print python 
Python :: django startapp in a folder,,while inside that folder 
Python :: python concurrent.futures.ProcessPoolExecutor multiple arguments 
Python :: a list of available font in figlet in python 
Python :: Count occurrence of each term in dataframe except for NaN 
Python :: np.column_sytaxck 
Python :: write yaml file without deleting content 
Python :: run php websevrer with python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =