df = pd.DataFrame({'D': [1, 2, 3], 'B': [5,1,6]})
df['D'] = df['D'] / df['B']
# That`s ok
df['D'][0] = 5
df.loc[0, 'D'] = 5
d = pd.DataFrame({'D': [1, 2, 3], 'B': [2, 3, 4]}, index=[1,2,3])
print(d['D'][4]
# Out: KeyError: 4
and
list_with_int_and_str = [1, '1', '2', 3, 5]
numbers = [1, 2, 3, 4, 5]
print([i for i in numbers if int(i) not in list_with_int_and_str and str(i) not in list_with_int_and_str])
# Out: [4]
n = 19
numbers_as_string = '16 11 5 7 15 18 6 13 9 10 14 12 2 19 4 17 3'
numbers = [int(i) for i in numbers_as_string.split(' ')]
all_numbers = set(range(1, n + 1))
numbers = set(numbers)
sorted_diff = [str(i) for i in sorted(all_numbers.difference(numbers))]
print(' '.join(sorted_diff))
def some_func(var1: int, list1: List[int, str], dict1: Dict[str, List[int]]) -> Tuple[str, str]:
# some logic
result1 = # some string result
result2 = # some string result
return result1, result2
def some_func(var1, list1, dict1):
# some logic
result1 = # some string result
result2 = # some string result
return result1, result2
df['date'] = pd.to_datetime(df[['year', 'month']].assign(day=1))
prices={
"Samsung 20": 300,
"Iphone 6S": 260,
"Lenovo Legion": 450
}
sells={
"Маша":"Samsung 20",
"Максим":"Iphone 6S",
"Наташа":"Lenovo Legion"
}
phones = [key for key, value in prices.items() if value < 350]
seller_names = [key for key, value in sells.items() if value in phones]
# Out: ['Маша', 'Максим']
datareport = pd.DataFrame({'ODATE': {0:0},
'TENOR': {0:0},
'VDATE': {0:0},
'R': {0:0},
'RC': {0:0},
'DE': {0:0},
'I': {0:0},
'DEB': {0:0},
'D': {0:0}}
datareport = pd.concat([datareport, pd.DataFrame({'ODATE': {0:row.odate},
'TENOR': {0:tenor(row.ltt)},
'VDATE': {0:row.vdate},
'R': {0:bucket_class_old},
'RC': {0:buckclass(row.odues)},
'DE': {0:row.ball},
'I': {0:0},
'DEB': {0:ball_old},
'D': {0:0}})])
datareport = pd.concat([datareport, pd.DataFrame({'ODATE': {0:row.odate},
'TENOR': {0:tenor(row.ltt)},
'VDATE': {0:row.vdate},
'R': {0:bucket_class_old},
'RC': {0:100},
'DE': {0:difference},
'I': {0:0},
'DEB': {0:ball_old},
'D': {0:0}})])
ser1 = pd.Series({'ODATE': 0,
'TENOR': 0,
'VDATE':0,
'R': 0,
'RC': 0,
'DE': 0,
'I': 0,
'DEB': 0,
'D': 0})
ser2 = pd.Series({'ODATE': 0,
'TENOR': 1,
'VDATE':2,
'R': 3,
'RC': 4,
'DE': 5,
'I': 6,
'DEB': 7,
'D': 8})
df = pd.concat([ser1, ser2], axis=1).T
datareport1 = pd.DataFrame({'ODATE': {0:0},
'TENOR': {0:0},
'VDATE': {0:0},
'R': {0:0},
'RC': {0:0},
'DE': {0:0},
'I': {0:0},
'DEB': {0:0},
'D': {0:0}})
datareport2 = pd.DataFrame({'ODATE': {0:1},
'TENOR': {0:2},
'VDATE': {0:3},
'R': {0:4},
'RC': {0:5},
'DE': {0:6},
'I': {0:7},
'DEB': {0:8},
'D': {0:9}})
df2 = pd.concat([datareport1, datareport2])
import pandas as pd
data = pd.read_csv('list.csv', sep=';')
def get_user_by_id(id, data):
data = data.loc[data['id'] == id, ['nick', 'name']]
name = data['name'][0]
nick = data['nick'][0]
return {'name': name, 'nick': nick}
print(get_user_by_id(1, data))
# Out: {'name': 'Test1', 'nick': '@test1'}
x if -x not in arr
не может существовать без блока else, то есть нужно вот так return x if -x not in arr else None
import pandas as pd
d = {'q': [1.5,2.2,3], 'w': [2,3,4]}
df = pd.DataFrame(d)
df.loc[0, 'q'].tolist()
# Out: 1.5
e = c.loc['2020-08-14', 'Open']
df.loc[[0, 1], 'q'].tolist()
# Out: [1.5, 2.2]
df.loc[[0, 1], 'q'].values
# Out: array([1.5, 2.2])
from sqlalchemy import create_engine
engine = create_engine('Your database params')
table = 'Some_Table'
sql_expression = f"""INSERT INTO {table} VALUES (1,1,1,1,1,1)"""
engine.execute(sql_expression)
INSERT INTO Some_Table VALUES (1,1,1,1,1,1)
sql_expression = f"""INSERT INTO {table} VALUES ('qwe','qw',1,1,'qwerty',1)"""
INSERT INTO Some_Table VALUES ('qwe','qw',1,1,'qwerty',1)
table = 'Some_Table'
value1 = 'test'
value2 = 'test2'
value3 = 1
value4 = 2
value5 = 'test3'
value6 = 3
sql_expression = f"""INSERT INTO {table} VALUES ('{value1}', '{value2}', {value3}, {value4}, '{value5}', {value6})"""
INSERT INTO Some_Table VALUES ('test', 'test2', 1, 2, 'test3', 3)