<commit_before>#!/usr/bin/env python
# encoding=utf8

"""

SYNOPSIS

DESCRIPTION

EXAMPLES

AUTHOR

LICENSE

VERSION  

"""

import pandas as pd
import numpy as np

'Assign some random values'
df = pd.DataFrame({ 
    'A' : np.random.randint(5, size=10),
    'B' : np.random.randint(5, size=10),
})

'Recode into column C with some operations'
df['C'] = 0.0

df['C'] = (df['A'] + df['B']) * 0.25

# Print DataFrame
print df

# Print Column Attributes
print df.dtypes

'Recode with floats'
df2 = pd.DataFrame({
    'A' : [1,2,3,4,5]  
})

df2['B'] = df2['A'].astype(float).replace([1, 2, 3, 4, 5], [1, 0.85, 0.70, 0.55, 0.40])

df2['C'] = df2['A'].map(dict(zip([1, 2, 3, 4, 5], [1, 0.85, 0.70, 0.55, 0.40])))

# Print DataFrame
print df2

# Print Column Attributes
print df2.dtypes<commit_msg>Recode with column means<commit_after>#!/usr/bin/env python
# encoding=utf8

"""

SYNOPSIS

DESCRIPTION

EXAMPLES

AUTHOR

LICENSE

VERSION  

"""

import pandas as pd
import numpy as np

'Assign some random values'
df = pd.DataFrame({ 
    'A' : np.random.randint(5, size=10),
    'B' : np.random.randint(5, size=10),
})

'Recode into column C with some operations'
df['C'] = 0.0

df['C'] = (df['A'] + df['B']) * 0.25

# Print DataFrame
print df

# Print Column Attributes
print df.dtypes

'Recode with floats'
df2 = pd.DataFrame({
    'A' : [1,2,3,4,5]  
})

df2['B'] = df2['A'].astype(float).replace([1, 2, 3, 4, 5], [1, 0.85, 0.70, 0.55, 0.40])

df2['C'] = df2['A'].map(dict(zip([1, 2, 3, 4, 5], [1, 0.85, 0.70, 0.55, 0.40])))

# Print DataFrame
print df2

# Print Column Attributes
print df2.dtypes

'Write condtional column means into a new column'
df3 = pd.DataFrame({
    'VAR_1' : [1,2,3,4,5], 
    'VAR_2' : [1,1,1,3,3],
    'GROUP': [1,1,1,2,2],
})

df3["GROUP_MEAN"] = df3.groupby('GROUP')['VAR_1'].transform('mean')

# Print DataFrame
print df3

# Print Column Attributes
print df3.dtypes
{'fraction_non_alphanumeric': 0.19862651875330165, 'fraction_numerical': 0.07554146856840993, 'mean_word_length': 3.7949367088607593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1601767', 'n_tokens_mistral': 891, 'n_tokens_neox': 825, 'n_words': 207}