我创建了一个循环来将 sqlite 数据库读入 Pandas 数据帧,并且我试图将它们合并在一起 "Code"
...
df = pandas.Dataframe() # Creating an empty dataframe for merging at the end
items = ["tb1", "tb2", "tb3"]
for each_item in items:
my_value = pandas.read_sql_query('select "Code", "Name", "Value" from {tb_name} where "Value" is not null'
.format(tbl_name='"%s"' % each_item), con=engine)
print(my_value)
# This below code is my attempt to merge the dataframes that was obtained through the for loop
merge_value = pandas.merge(my_value, df, on='Code', how='outer')
Run Code Online (Sandbox Code Playgroud)
my_value 结果:
# tb1 results
Code Name Value
0 …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码创建了一个数据框列,并试图弄清楚如何将其舍入到最近的100.
...
# This prints out my new value rounded to the nearest whole number.
df['new_values'] = (10000/df['old_values']).apply(numpy.floor)
# How do I get it to round down to the nearest 100th instead?
# i.e. 8450 rounded to 8400
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码将查询结果打印到控制台,但它始终向我返回对象位置。
test = connection.execute('SELECT EXISTS(SELECT 1 FROM "my_table" WHERE Code = 08001)')
print(test)
Run Code Online (Sandbox Code Playgroud)
我得到的结果是- <sqlalchemy.engine.result.ResultProxy object at 0x000002108508B278>
如何打印出value而不是对象?
我问的原因是因为我想使用该值进行比较测试。例如:
if each_item not in test:
# do stuffs
Run Code Online (Sandbox Code Playgroud) 我有以下代码,我试图从https://www.quandl.com/data/TSE/documentation/metadata获取数据.(试图获取下载详细数据)
for page_number in range(1, 5):
link = r'https://www.quandl.com/api/v3/datasets.csv?database_code=TSE&per_page=100&sort_by=id&page=' + str(page_number)
r = requests.get(link, stream=True).text
print(r)
# How to put the results in a dataframe?
Run Code Online (Sandbox Code Playgroud)
但是,我无法将结果放在数据框中/将其保存在SQLite数据库中.我该怎么做?
我有我的文件夹中的几个文件xyz_driver,xyz_tool,xyz_mac,aaa_driver,aaa_tool,aaa_mac
如果我这样做的话
for filename in glob.glob('xyz_driver'):
os.remove(filename)
Run Code Online (Sandbox Code Playgroud)
有用.
但我怎么删除所有文件只有当名称开头xyz?
我有一个从以下代码获得的数据框,但无法将date索引转换为dd / mm / yyyy
df= pandas.read_html(base_url, header=0, index_col='Date', parse_dates=True)[0]
df.index = pandas.to_datetime(df.index, dayfirst=True)
Run Code Online (Sandbox Code Playgroud)
这是结果
Col1 Col2
Date
2017-02-10 val1 val1
2017-02-09 val2 val2
2017-02-08 val3 val3
2017-02-07 val4 val4
Run Code Online (Sandbox Code Playgroud)
我已经厌倦了我在stackoverflow上搜索的其他几个不同的变体,但是我找不到适合的组合。
它仍然打印出dateasyyyy-mm-dd
我正在尝试在 kotlin 中创建一个嵌套数据类,其中包含其他几个数据类。然后访问主数据类来获取嵌套数据类的对象。
Person数据类将成为标准,但其他 3 个数据类是重载的(不确定我在这里是否正确使用了术语“重载”?)。
注意:我使用的IDE是intellij
我的意思是说:
data class User(val person: Person, val transport: Transport)
{
constructor(person: Person, activity: Activity): this(person, activity) //ERROR: There's a cycle in the delegation calls chain
constructor(person: Person, absent: Absent): this(person, absent) //ERROR: There's a cycle in the delegation calls chain
}
data class Activity(val game: String, val funLevel: Int)
data class Absent(val isSick: Boolean, val funLevel: Int)
data class Transport(val typeOfTransport: String)
data class Person(val name: String, val age: Int)
fun main(){ …Run Code Online (Sandbox Code Playgroud)