索引DataFrame值,直到达到值/字符串

时间:2017-03-01 15:38:27

标签: python excel oracle

我有一个Excel电子表格,我想将基本数据导出到我的Oracle表格中。

Excel表格在某些单元格中有额外的不必要数据。它也在中途分开,表明可用鱼和所需鱼之间的差异。我需要捕捉这种差异。

所以我的目标是导出所有数据,但在我的Oracle数据库中,我需要区分提供的鱼和所需的鱼。那么有没有一种方法来索引列,直到索引达到QUOTA TO BUY?因此,允许我在1列中导出带有ask的第一个块,然后在我的1列中导出第

bid
import os import numpy as np import pandas as pd import cx_Oracle import re from dateutil import parser dsnStr = cx_Oracle.makedsn("sole.noaa.gov", "1526", "sole") con = cx_Oracle.connect(user="user", password="passsword", dsn=dsnStr) path = 'Z:\\excel_file_to_convert' #pattern = re.compile(r'Sent:(.+?)(?=<br/>)') for filename in os.listdir(path): file_path = os.path.join(path, filename) if os.path.isfile(file_path): df = pd.read_excel(file_path) print("df is:", df) print("column 1 I think:", df[:DESIRED STOCK]) print("row 1:", df.loc[0]) print("row 2:", df.loc[1]) print("row 3:", df.loc[2]) print("row 4:", df.loc[3]) print("row 5:", df.loc[4]) #d = parser.parse(df, fuzzy=True) #print(d) #df['DATE'] = pd.to_datetime(df['DATE']) # convert date column to datetimes #latest_date = df['DATE'].max() # find the latest datetime #latest_rows = df[df['DATE'] == latest_date] # use index filtering to choose only columns equal to latest date #print ("latest_rows is:", latest_rows) cursor = con.cursor() exported_data = [tuple(x) for x in df.values] sql_query = ("INSERT INTO ROUGHTABLE(species, date_posted, stock_id, pounds, money, sector, ask)" "VALUES(:3, :1, :2, :4, :5, 'Sustainable Harvest Sector', '1')") #sql_query = ("INSERT INTO DATABASE(species, trade_date, trade_id, pounds, advertised_price, email_year, email_month, email_day, sector, ask)" "VALUES(:3, :1, :2, :4, :5, :6, :7, :8, 'Sustainable Harvest Sector', '1')") cursor.executemany(sql_query, exported_data) con.commit() #commit to database cursor.close() con.close()

我到目前为止尝试的代码如下,以及Excel表的图片。谢谢你的帮助。

enter image description here

/* Programmer: Joshua Zuber
   Program Desc: This is a game that can keep track of players scores!
   Program Name:  Score Tracker
   Clean Compile Date: 
*/

#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include <vector>



using namespace std;

int main()

{

    // Player Variables

    string player1
    string player2;
    string player3;
    string player4;
    string player5;


    // Variables
    char again = 'y';
    char menu1 = 'y';
    int pNumb;

    // Game Arrays
    string player1G[] = "";
    string player2G[] = "";
    string player3G[] = "";
    string player4G[] = "";
    string player5G[] = "";

    // Score Arrays
    string player1S[] = "";
    string player2S[] = "";
    string player3S[] = "";
    string player4S[] = "";
    string player5S[] = "";




    while (toupper(again) == 'Y')
    {
        cout << "Welcome to Score Tracker!" << "\n\n";


        while (toupper(menu1) == 'Y')
        {
            cout <<  "1. "  << player1 << "\n\n";
            cout <<  "2. "  << player2 << "\n\n";
            cout <<  "3. "  << player3 << "\n\n";
            cout <<  "4. "  << player4 << "\n\n";
            cout <<  "5. "  << player5 << "\n\n";
            cout << "Please select a player to add your favorite games and scores!";
            cin >> pNumb;
            system("cls");


            if (pNumb == 1)
            {
                cout << "Please enter a name for player 1!" << "\n\n";
                cin >> player1;
                cin.getline(player1);
                cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
                     cin >> menu1 ; 
                     system("cls");
            }
        }
    }
} 

1 个答案:

答案 0 :(得分:0)

除非您需要反复执行此操作,否则您无需使用其他语言。

将其粘贴到单元格boost::gregorian::date_facet中,然后将其复制到要插入第一个块中的所有行。

F4

将生成的SQL语句复制并粘贴到脚本中,然后在SQL / Plus中运行。

然后,您可以编辑第二个块的公式并根据需要重复该过程。