for i in range(200):
driver.execute_script("var evt = document.createEvent('MouseEvents');evt.initEvent('wheel', true, true);evt.deltaY = -100000;document.querySelector('.yamb-conversation__content').dispatchEvent(evt);")
time.sleep(2)
html2 = driver.page_source
soup2 = BeautifulSoup(html2, 'lxml')
df = pd.DataFrame([{'name': '"name1"', 'status': '"ok"'}, {'name': '"name2"', 'status': '"ok"'}])
>>> df
name status
0 "name1" "ok"
1 "name2" "ok"
>>> for col in df.columns.values:
... df[col] = df[col].str.strip('"')
...
>>> df
name status
0 name1 ok
1 name2 ok
>>> df[df.columns] = df.apply(lambda x: x.str.strip('"'))
>>> df
name status
0 name1 ok
1 name2 ok
from pprint import pprint
import pandas as pd
dic = [
{'name': 'Pavel', 'id': '233082', 'pos': ['85742', '95380', '40979']},
{'name': 'Oleg', 'id': '233082', 'pos': ['81052', '8316', '3062']},
{'name': 'Oleg', 'id': '233082', 'pos': ['41052', '5318', '2304']},
{'name': 'Oleg', 'id': '233082', 'pos': ['21050', '1317', '9305.']},
{'name': 'Nikolay', 'id': '233082', 'pos': ['25781', '94116', '20264']},
]
df = pd.DataFrame(dic)
# print(df)
# name id pos
# 0 Pavel 233082 [85742, 95380, 40979]
# 1 Oleg 233082 [81052, 8316, 3062]
# 2 Oleg 233082 [41052, 5318, 2304]
# 3 Oleg 233082 [21050, 1317, 9305.]
# 4 Nikolay 233082 [25781, 94116, 20264]
foo = {'pos': lambda rows: [x for x in rows] if len(rows) > 1 else rows, 'name': 'first', 'id': 'first'}
df = df.groupby('name').aggregate(foo).to_dict(orient='record')
# pprint(df)
# [{'id': '233082', 'name': 'Nikolay', 'pos': ['25781', '94116', '20264']},
# {'id': '233082',
# 'name': 'Oleg',
# 'pos': [['81052', '8316', '3062'],
# ['41052', '5318', '2304'],
# ['21050', '1317', '9305.']]},
# {'id': '233082', 'name': 'Pavel', 'pos': ['85742', '95380', '40979']}]
>>> df = pd.DataFrame([{'name': 'example', 'email': 'example@example.com'}, {'name': 'example2', 'email': 'example2@example.com'}])
>>> df
name email
0 example example@example.com
1 example2 example2@example.com
>>> for _, row in df.iterrows():
... row['email']
...
'example@example.com'
'example2@example.com'
>>> import pandas as pd
>>> df = pd.read_csv('sample.csv')
>>> df
id images
0 0 https://image.png?width=640
1 1 https://image2.png?width=640
2 2 https://image3.png?width=640
>>> df['images'] = df['images'].str.split('?').str[0]
>>> df
id images
0 0 https://image.png
1 1 https://image2.png
2 2 https://image3.png
import csv
>>> with open('sample.csv', 'r') as f:
... rows = list(csv.DictReader(f))
...
>>> rows
[OrderedDict([('id', '0'), ('images', 'https://image.png?width=640')]), OrderedDict([('id', '1'), ('images', 'https://image2.png?width=640')]), OrderedDict([('id', '2'), ('images', 'https://image3.png?width=640')])]
>>> rows = [{k: v.split('?')[0] if k=='images' else v for k, v in row.items()} for row in rows]
>>> rows
[{'id': '0', 'images': 'https://image.png'}, {'id': '1', 'images': 'https://image2.png'}, {'id': '2', 'images': 'https://image3.png'}]
import requests
from requests.auth import HTTPBasicAuth
import base64
import json
def run():
account_id = 'f802238b-58****ab51-2989606f4745'
key = base64.b64encode(bytes('3_0KgI4JvUDQNLcluZYnzA4YCad'))
auth = HTTPBasicAuth(account_id, key)
url = 'https://smartcat.ai/api/integration/v1/project/create'
with open("project.json","r") as f:
project = json.load(f)
headers = {'Content-Type': 'application/json'}
response = requests.post(url, data=project, headers=headers, auth=auth)
print(response)
run()