Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Manipulacao de JSON object

Como eu executaria as seguintes mudancas:

Given the JSON object {"sku": "VA-43", "size": "5ft", "name": "Blue Sky", "description": "A great product!"}*

1) All values must be lowercase.

2) Values may contain only alphanumeric characters, underscores or dots. All other characters must be replaced with underscores.

3) "description" is a special property, to which none of the above specifications apply.

4) If any value has more than 10 characters, trim it at 10 characters and add three trailing dots.

5) Convert imperial units into metric. For distance, use meters.

Tentando fazer isso vi como aprendi muito pouco.

1 resposta
solução!

O jeito que consegui rodar esse codigo foi assim:

import pandas as pd

json_object = { "sku": ["VA-43"], "size": ["5ft"], "name": ["Blue Sky"], "description": ["A great product!"] }

df = pd.DataFrame.from_dict(json_object)

df['sku'] = df['sku'].str.lower()

df['sku'] = df['sku'].str.replace(r'\W', "_")

df['size'] = df['size'].str.lower().replace(r'\W', "_")

df['size'] = df['size'].str.replace(r'\W', "_")

df['name'] = df['name'].str.lower().replace(r'\W', "_")

df['name'] = df['name'].str.replace(r'\W', "_")

def counting(string): var_e = len(string) - 6 if len(string) > 10: return string[:var_e]+ '...'

else: return string

df = df.applymap(counting)

df['size'] = df['size'].apply(lambda x : x.split('f')[0]) df['size'] = str(int(df['size']) * 0.3048) + 'm' df

gostaria de inserir uns for loops, mas nao sei qual a syntax