I have a dataframe that contains codes with one letter and three digits maximum, ex: A478. Some codes only have one or two digits, but I need to put a point before all values that have three digits, to transform them in the form: A213 to A21.3 In short, I need to transform the df […]

Categories

## Given a condition, modify values of a dataframe

- Post author By Full Stack
- Post date September 12, 2019
- No Comments on Given a condition, modify values of a dataframe

- Tags but i get an invalid syntax, but I need to put a point before all values that have three digits, ex: A478. Some codes only have one or two digits, I have a dataframe that contains codes with one letter and three digits maximum, I need to transform the df in this way: id code1 code2 code3 code4 0 A099 B25 A022 NaN 1 B21 J2 Z23 H355 2 C212 C03 NaN NaN, so I don't know how to evaluate the condition of it happening only if it has three digits (or 4 str). df.apply(lambda x: x.str[:3]+'.'+x.str, to transform them in the form: A213 to A21.3 In short