pandasql

Pandas - Using 'ffill' on values other than Na

吃可爱长大的小学妹 提交于 2021-01-27 16:43:59
问题 Is there a way to use ffill method on values that are not NaN ? I have NaN in my dataframe, but I have added these NaN using addNan = sample['colA'].replace(['A'], 'NaN') So this is what my DataFrame, df looks like ColA ColB ColC ColD B A A C NaN B A A C D D A NaN A A B And I'm trying to fill these NaN using ffill , so they are populated by the last known value. fill = df.fillna(method='ffill', inplace = True) This doesn't make a difference, also tried Na instead of NaN 回答1: I think you need

Pandas - Using 'ffill' on values other than Na

我的梦境 提交于 2021-01-27 16:42:41
问题 Is there a way to use ffill method on values that are not NaN ? I have NaN in my dataframe, but I have added these NaN using addNan = sample['colA'].replace(['A'], 'NaN') So this is what my DataFrame, df looks like ColA ColB ColC ColD B A A C NaN B A A C D D A NaN A A B And I'm trying to fill these NaN using ffill , so they are populated by the last known value. fill = df.fillna(method='ffill', inplace = True) This doesn't make a difference, also tried Na instead of NaN 回答1: I think you need

How to Insert Huge Pandas Dataframe in MySQL table with Parallel Insert Statement?

孤人 提交于 2020-05-27 10:45:32
问题 I am working on a project where I have to write a data frame with Millions of rows and about 25 columns mostly of numeric type. I am using Pandas DataFrame to SQL Function to dump the dataframe in Mysql table. I have found this function creates an Insert statement that can insert multiple rows at once. This is a good approach but MySQL has a limitation on the length of query that can be built using this approach. Is there a way such that insert that in parallel in the same table so that I can

Using user input variables in PandaSQL

依然范特西╮ 提交于 2019-12-24 10:27:55
问题 I'm trying to use pandaSQL on a dataframe that I have and I'm wondering if there's a way to use variables or if there's another way to do it. What I'm trying to do is setting user input as a variable and then trying to use that in the SQL statement. I want to display every instance that a shape when input. I'm trying stuff along the lines of: variable1 = input("Enter shape here: ") print pysqldf("SELECT imageNum FROM df WHERE shape1 = variable1 ") but so far no luck. Everything else is

Using dictionary values in pandasql

房东的猫 提交于 2019-12-24 00:48:48
问题 I have a dictionary that has dataframes in values, something like this - mydict = {'demand': demand_df, 'supply':supply_df, 'prod': prod_df} Then I am using pandasql module to execute a simple query. query = "SELECT * FROM mydict['demand']" print(ps.sqldf(query)) This is giving out an error - AttributeError: 'dict' object has no attribute 'index' However, if I add an extra step, it does work - demand = mydict['demand'] query = "SELECT * FROM demand" print(ps.sqldf(query)) How do I work with

Combine similar rows to one row in python dataframe

孤者浪人 提交于 2019-12-12 06:48:47
问题 I have some dataframe as below, what I want to do is to combine the rows with same "yyyymmdd" and "hr " into one row. (there are several rows with same "yyyymmdd" and "hr" ) yyyymmdd hr ariel cat kiki mmax vicky gaolie shiu nick ck 10 2015-12-27 9 0 0 0 0 0 0 0 23 0 181 2015-12-27 10 0 0 0 0 0 0 0 2 0 65 2015-12-27 11 0 0 0 0 0 0 0 20 0 4 2015-12-27 12 0 0 0 0 0 0 0 4 0 0 2015-12-27 17 0 0 0 0 0 0 0 2 0 141 2015-12-27 19 1 0 0 0 0 0 0 0 0 160 2015-12-28 8 0 8 0 0 0 0 0 0 0 82 2015-12-28 9 0 0

How to properly implement indexing for use in variable LIKE statement with sqlite3?

孤街醉人 提交于 2019-12-11 15:09:55
问题 I am trying to do some fuzzy matching between two tables. One is a table I have stored locally (9,000 rows), call it table A. The other is stored as a sqlite db (2 million + rows csv), call it table B. Basically, I want to match the column "CompanyNames" from table A with the column "CurrentEntityNames" from table B and use this to left join table B to table A. I am currently able to loop through the LIKE statements, passing a parameter like so: (myNames is just the column CompanyNames from

Pandas IO SQL and stored procedure with multiple result sets

。_饼干妹妹 提交于 2019-12-11 13:45:07
问题 So I have a stored proc on a local sql server, this returns multiple data sets / tables Normally, in python / pyodbc I would use cursor.nextset() subset1 = cursor.fetchall() cursor.nextset() subset2 = cursor.fetchall() I wish to make use of the ps.io.sql.read_sql and return the stored procedure with multiple result sets into dataframes, however I can not find anything that references how to move the cursor along and get more information before closing things off. import pandas as ps query =

Pandas dataframe transpose with column name instead of index throws ValueError

↘锁芯ラ 提交于 2019-12-11 05:58:03
问题 I am trying to show actual column name in json after dataframe has been transposed, below code works for LIMIT 3 in sql but fails if I try LIMIT 5 Any thoughts please? from pandasql import * pysqldf = lambda q: sqldf(q, globals()) q1 = """ SELECT beef as beef, veal as veal, pork as pork, lamb_and_mutton as lamb FROM meat m LIMIT 5; """ meat = load_meat() df = pysqldf(q1) #print(df.to_json(orient='records')) hdf = pd.DataFrame(df) print(hdf.T.reset_index().set_axis(range(len(hdf.columns)),

Merging DataFrames on multiple conditions - not specifically on equal values

混江龙づ霸主 提交于 2019-11-29 04:26:46
Firstly, sorry if this is a bit lengthy, but I wanted to fully describe what I have having problems with and what I have tried already. I am trying to join (merge) together two dataframe objects on multiple conditions. I know how to do this if the conditions to be met are all 'equals' operators, however, I need to make use of LESS THAN and MORE THAN. The dataframes represent genetic information: one is a list of mutations in the genome (referred to as SNPs) and the other provides information on the locations of the genes on the human genome. Performing df.head() on these returns the following: