def test_read_clipboard_infer_excel(self):
        # gh-19010: avoid warnings
        clip_kwargs = dict(engine="python")

        text = dedent("""
            John James	Charlie Mingus
            1	2
            4	Harry Carney
            """.strip())
        clipboard_set(text)
        df = pd.read_clipboard(**clip_kwargs)

        # excel data is parsed correctly
        assert df.iloc[1][1] == 'Harry Carney'

        # having diff tab counts doesn't trigger it
        text = dedent("""
            a\t b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        res = pd.read_clipboard(**clip_kwargs)

        text = dedent("""
            a  b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        exp = pd.read_clipboard(**clip_kwargs)

        tm.assert_frame_equal(res, exp)
 def test_invalid_encoding(self):
     # test case for testing invalid encoding
     data = self.data['string']
     with tm.assertRaises(ValueError):
         data.to_clipboard(encoding='ascii')
     with tm.assertRaises(NotImplementedError):
         pd.read_clipboard(encoding='ascii')
Exemple #3
0
    def test_read_clipboard_infer_excel(self):

        text = dedent("""
            John James	Charlie Mingus
            1	2
            4	Harry Carney
            """.strip())
        clipboard_set(text)
        df = pd.read_clipboard()

        # excel data is parsed correctly
        assert df.iloc[1][1] == 'Harry Carney'

        # having diff tab counts doesn't trigger it
        text = dedent("""
            a\t b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        res = pd.read_clipboard()

        text = dedent("""
            a  b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        exp = pd.read_clipboard()

        tm.assert_frame_equal(res, exp)
Exemple #4
0
    def test_read_clipboard_infer_excel(self):
        from textwrap import dedent
        from pandas.util.clipboard import clipboard_set

        text = dedent("""
            John James	Charlie Mingus
            1	2
            4	Harry Carney
            """.strip())
        clipboard_set(text)
        df = pd.read_clipboard()

        # excel data is parsed correctly
        self.assertEqual(df.iloc[1][1], 'Harry Carney')

        # having diff tab counts doesn't trigger it
        text = dedent("""
            a\t b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        res = pd.read_clipboard()

        text = dedent("""
            a  b
            1  2
            3  4
            """.strip())
        clipboard_set(text)
        exp = pd.read_clipboard()

        tm.assert_frame_equal(res, exp)
Exemple #5
0
 def check_round_trip_frame(self, data_type, excel=None, sep=None):
     data = self.data[data_type]
     data.to_clipboard(excel=excel, sep=sep)
     if sep is not None:
         result = read_clipboard(sep=sep,index_col=0)
     else:
         result = read_clipboard()
     tm.assert_frame_equal(data, result, check_dtype=False)
 def set_data_clipboard(self, column):
     s = clipboard.paste()
     s_var = s
     n = s.count('\t', 0, s.find('\n'))
     header = ''
     for i in self.HeaderLabels[column:column+n+1]:
         header += i + '\t'
     header = header[:-1]
     header = header + '\n'
     s = header + s
     clipboard.copy(s)
     try:
         data = pd.read_clipboard()
         for i in data.keys():
             self.data[i] = remove_nan(data[i])
         self.logger.info('Data loading from clipboard successfully')
         self.notify_observers()
     except (MyException, IsnanInput) as e:
         print(e)
         self.logger.info('Data loading error; Check clipboard values')
         self.logger.error(str(e))
     finally:
         clipboard.copy(s_var)
         self.datastatus = self.check_datastatus()
         if self.datastatus == 'full' or self.datastatus == 'partlyfull':
             self.step_E = self.data['Xe'][1]-self.data['Xe'][0]
             self.step_L = self.data['Xl'][1]-self.data['Xl'][0]
             self.notify_observers_datastatus()
def getchart():
  '读取剪切板的期货或股票的历史导出数据,输出均价、成交量、持仓量等信息'
  read=pd.read_clipboard(header=0,index_col=0)
  #转化为pandas的timeindex格式,方便对数据重新取样
  index=pd.to_datetime(read.index)
  #处理labels和llabel's name
  read.index=index
  read.index.name=""

  if len(read.columns)==8:
    '''对期货(主力合约和具体合约)都具有八列,如铁矿石I.DCE:
    日期	开盘价(元)	最高价(元)	最低价(元)	收盘价(元)	结算价	成交额(百万)	成交量	持仓量
    2016-03-15	419.5	428	410.5	413	419.5	203805.42	4856536	1039788
    2016-03-16	410.5	421	410	419	415.5	138065.06	3321042	1061572
    2016-03-17	420.5	436.5	416	435.5	426	188942.64	4432586	1086568
    2016-03-18	435.5	451.5	433.5	449.5	445	175160.16	3934660	933232
    2016-03-21	414	431	410	422.5	423.5	208160.62	4910998	1231352
    '''
    read['投机度']=read.成交量/read.持仓量
    read['投机度'].plot()
    sample=read.resample('3M').mean().iloc[:,[-1,-5,-4,-2]]
    sample.plot(subplots=True, layout=(2, 2), figsize=(10, 6), sharex=False);
  else:
    '''
    对股票来说,只有六列,如同仁堂(6000085)
    日期	开盘价(元)	最高价(元)	最低价(元)	收盘价(元)	成交额(百万)	成交量
    2016-04-14	29.95	30	29.69	29.88	270.52	9072700
    2016-04-15	29.97	30	29.75	29.83	190.35	6381000
    2016-04-18	29.8	29.81	29.18	29.2	228.48	7785300
    2016-04-19	29.31	29.43	28.91	29.1	161.17	5541900
    2016-04-20	29.15	29.28	27.11	28.4	391.68	13885100
    '''
    read['成交均价']=read['成交额(百万)']/read['成交量']
    sample=read.resample('3M').mean().iloc[:,[-1,-4,-3,-2]]
    sample.plot(subplots=True, layout=(2, 2), figsize=(10, 6), sharex=False)
Exemple #8
0
def test_from_clipboard():
    setup_clipboard(SMALL_ROW_SIZE)

    pandas_df = pandas.read_clipboard()
    modin_df = pd.read_clipboard()

    assert modin_df_equals_pandas(modin_df, pandas_df)
Exemple #9
0
def calculate_volatility(days=60):
    '将行情数据复制至剪切板后,计算给定天数的波动率'
    days = days
    data = pd.read_clipboard()
    b = data['收盘价(元)']
    data['log_return'] = log(b / b.shift(1))
    sigma = data['log_return'][-(days):].describe()['std'] * 260**0.5
    return sigma
Exemple #10
0
def inquire_position(path):
    app = Application().connect(path=path)
    app[u"网上股票交易系统5.0"]["CVirtualGridCtrl"].click_input()
    SendKeys.SendKeys('W')
    SendKeys.SendKeys('{F5}')
    app[u"网上股票交易系统5.0"]["CVirtualGridCtrl"].TypeKeys('^c')
    data = pd.read_clipboard()
    return data
Exemple #11
0
def select_names_from_clipboard(df):
    import pandas as pd
    import numpy as np
    names = pd.read_clipboard()
    names = names.replace({'proměnná': np.nan}).dropna()
    print('počet vybraných proměnných je ', len(names))
    cols = names.ix[:,0].tolist()
    return df.ix[:, cols]
Exemple #12
0
def exercise129():
    pd.read_csv('titanic.csv')
    pd.read_csv('weather.txt')
    pd.read_excel('foo.xlsx')
    # db = create_engine('sqlite:///pandasdb.db')
    # pd.read_sql(
    #     ('select "Timestamp","Value" from "MyTable" '
    #      'where "Timestamp" BETWEEN %(dstart)s AND %(dfinish)s'),
    #     db, params={
    #         "dstart": datetime(2014, 6, 24, 16, 0),
    #         "dfinish": datetime(2014, 6, 24, 17, 0)
    #     }, index_col=['Timestamp'])
    pd.read_json('https://raw.githubusercontent.com/chrisalbon/simulated_datasets/master/data.json', orient='columns')
    # make sure lxml, html5lib, bs4, is installed
    pd.read_html("https://pandasbootcamp.herokuapp.com/")
    pd.read_clipboard()
    pd.DataFrame(data)
Exemple #13
0
def clipboard2array():
    '''
    Return the clipboard as a numpy array using pandas.
    Useful for excel data.
    '''

    data = pd.read_clipboard(header=None)
    y = np.array(data.ix[:])
    return y
Exemple #14
0
def read_from_clipboard():
    """reads data from clipboard as a list of columns. Regex is applied to clean
    the data of any braces or quotes."""
    try:
        clipboard_data = pandas.read_clipboard(index_col=False, header=None).values
        clipboard_data = clean_text(str(clipboard_data))
    except ValueError:
        clipboard_data = False
    return clipboard_data
Exemple #15
0
def read_clipboard(sep=r'\s+'):

    warnings.warn("Defaulting to Pandas implementation",
                  PendingDeprecationWarning)

    port_frame = pd.read_clipboard(sep)
    ray_frame = from_pandas(port_frame, get_npartitions())

    return ray_frame
Exemple #16
0
def read_clipboard(sep=r'\s+'):

    warnings.warn("Defaulting to Pandas implementation",
                  PendingDeprecationWarning)

    port_frame = pd.read_clipboard(sep)
    ray_frame = from_pandas(port_frame, get_npartitions())

    return ray_frame
Exemple #17
0
def getTable():
    table = pd.read_clipboard(header = None, sep=r"[\[\]\t,\(\)]")
    max1 = table.ix[:, 1].max() + 1
    max2 = table.ix[:, 2].max() + 1
    max3 = table.ix[:, 3].max() + 1

    table = table.ix[:, 5].reshape((max1, max2, max3))
    
    return table
Exemple #18
0
    def get_statistics(self):
        self.select_all()
        self.open_text_utilities()
        self.get_tag_info(
            r'%album%;$ifequal($len(%length%),4,00:0%length%,00:%length%);%date%;%title%;%rating%;%genre%;%album artist%;$date(%added%);%play_count%;%artist%'
        )
        self.close()
        pdSongs = pd.read_clipboard(sep=';', encoding='utf-8')

        return pdSongs
Exemple #19
0
def normalise_terms_vector():
    """Use this to quickly copy a list of payment terms from Excel, and get a vector of normalised terms
    in return. Use to verify """
    dataset = pd.DataFrame()
    terms_df = pd.read_clipboard()
    terms = terms_df['0'].values.tolist()
    result = [gf.normalise(int(x)) for x in terms]
    dataset['Result'] = result
    dataset.to_clipboard(index=False)
    return
Exemple #20
0
 def check_round_trip_frame(self,
                            data,
                            excel=None,
                            sep=None,
                            encoding=None):
     data.to_clipboard(excel=excel, sep=sep, encoding=encoding)
     result = read_clipboard(sep=sep or "\t",
                             index_col=0,
                             encoding=encoding)
     tm.assert_frame_equal(data, result, check_dtype=False)
Exemple #21
0
    def open_clipboard_pressed(self):
        try:
            self.data = pd.read_clipboard()

            self.data_table.empty()
            table = [list(self.data.columns)] + [[str(x) for x in row] for row in self.data.values]
            self.data_table.from_2d_matrix(table)
        except Exception as e:
            self.text_message(repr(e))
        pass
Exemple #22
0
    def check_clipboard(self, event):
        '''
		'''
        print('buum')
        cb = self.toplevel.clipboard_get()
        df = pd.read_clipboard(header=None)
        rows = self.pt.multiplerowlist
        cols = self.pt.multiplecollist

        print(rows, cols)
Exemple #23
0
 def execute(self, context: FunctionContext, args: List = None) -> List:
     if self.kwargs is not None:
         tmp_args = self.kwargs
     else:
         tmp_args = {}
     if self.file_format.strip().lower() == "csv":
         return [
             pd.read_csv(filepath_or_buffer=self.file_or_buffer,
                         **tmp_args)
         ]
     elif self.file_format.strip().lower() == "json":
         return [
             pd.read_json(path_or_buf=self.file_or_buffer, **tmp_args)
         ]
     elif self.file_format.strip().lower() == "html":
         return [pd.read_html(io=self.file_or_buffer, **tmp_args)]
     elif self.file_format.strip().lower() == "clipboard":
         return [pd.read_clipboard(**tmp_args)]
     elif self.file_format.strip().lower() == "excel":
         return [pd.read_excel(io=self.file_or_buffer, **tmp_args)]
     elif self.file_format.strip().lower() == "hdf":
         return [
             pd.read_hdf(path_or_buf=self.file_or_buffer, **tmp_args)
         ]
     elif self.file_format.strip().lower() == "feather":
         return [pd.read_feather(path=self.file_or_buffer, **tmp_args)]
     elif self.file_format.strip().lower() == "parquet":
         return [pd.read_parquet(path=self.file_or_buffer, **tmp_args)]
     elif self.file_format.strip().lower() == "msgpack":
         return [
             pd.read_msgpack(path_or_buf=self.file_or_buffer,
                             **tmp_args)
         ]
     elif self.file_format.strip().lower() == "stata":
         return [
             pd.read_stata(filepath_or_buffer=self.file_or_buffer,
                           **tmp_args)
         ]
     elif self.file_format.strip().lower() == "sas":
         return [
             pd.read_sas(filepath_or_buffer=self.file_or_buffer,
                         **tmp_args)
         ]
     elif self.file_format.strip().lower() == "pickle":
         return [pd.read_pickle(path=self.file_or_buffer, **tmp_args)]
     elif self.file_format.strip().lower() == "sql":
         return [pd.read_sql(**tmp_args)]
     elif self.file_format.strip().lower() == "sql_query":
         return [pd.read_sql_query(**tmp_args)]
     elif self.file_format.strip().lower() == "sql_table":
         return [pd.read_sql_table(**tmp_args)]
     elif self.file_format.strip().lower() == "gbq":
         return [pd.read_gbq(**tmp_args)]
     else:
         raise Exception("pandas do not support " + self.file_format)
Exemple #24
0
 def parse_clipboard(self):
     
     clip_board_df = pd.read_clipboard()
     
     if clip_board_df is None:
         return
         
     if len(clip_board_df.columns) < 2:
         return 
         
     for index in clip_board_df.index:
         self.add_row(clip_board_df.ix[index])
Exemple #25
0
    def test_infer_excel_with_nulls(self, request, mock_clipboard):
        # GH41108
        text = "col1\tcol2\n1\tred\n\tblue\n2\tgreen"

        mock_clipboard[request.node.name] = text
        df = read_clipboard()
        df_expected = DataFrame(
            data={"col1": [1, None, 2], "col2": ["red", "blue", "green"]}
        )

        # excel data is parsed correctly
        tm.assert_frame_equal(df, df_expected)
Exemple #26
0
	def copy_from_clipboard(self,event):
		'''
		Try to infer paste as a valid input in the search entry.
		E.g separating each entry by comma and put string in ""
		'''
		data = pd.read_clipboard('\t',header=None).values.ravel()
		output = r''
		for value in data:
			output = output + r',"{}"'.format(value)
		self.outputString = output[1:]
		self.searchString.set(self.outputString)
		self.protectEntry = 0
Exemple #27
0
 def parse_clipboard(self):
     
     clip_board_df = pd.read_clipboard()
     
     if clip_board_df is None:
         return
         
     if len(clip_board_df.columns) < 2:
         return 
         
     for index in clip_board_df.index:
         self.add_clip_board_row(clip_board_df.ix[index])
Exemple #28
0
    def test_infer_excel_with_multiindex(self, request, mock_clipboard, multiindex):
        # GH41108

        mock_clipboard[request.node.name] = multiindex[0]
        df = read_clipboard()
        df_expected = DataFrame(
            data={"col1": [1, None, 2], "col2": ["red", "blue", "green"]},
            index=multiindex[1],
        )

        # excel data is parsed correctly
        tm.assert_frame_equal(df, df_expected)
def Df_from_clipboard():
    import clipboard
    import pandas as pd
    from pprint import pprint
    print(
        "\n\nThe DataFrame with variable name copied in your clipboard, please press CTRL+V\n\n"
    )
    c = pd.read_clipboard()
    s = str(c.to_dict())
    s = f"import pandas as pd, numpy as np; from numpy import nan\ndf = pd.DataFrame({s})\ndf"
    clipboard.copy(s)

    print(c.to_string())
Exemple #30
0
def wind():
    a = pd.read_clipboard().dropna().drop_duplicates()
    a.index = a.date
    b = a.iloc[:, 1:]
    b.index = a.date
    grouped = b.groupby(['type', 'ind'])
    for key, group in grouped:
        (group['wind_c'] / group.iloc[0, 2]).to_csv(
            r"C:\Users\gsyuan\Desktop\test0.csv", mode='a')
        (group['type']).to_csv(r"C:\Users\gsyuan\Desktop\test1.csv", mode='a')
        group.to_csv(r"C:\Users\gsyuan\Desktop\test2.csv",
                     mode='a',
                     header=False)
Exemple #31
0
    def test_read_clipboard_infer_excel(self, request, mock_clipboard):
        # gh-19010: avoid warnings
        clip_kwargs = dict(engine="python")

        text = dedent(
            """
            John James	Charlie Mingus
            1	2
            4	Harry Carney
            """.strip()
        )
        mock_clipboard[request.node.name] = text
        df = pd.read_clipboard(**clip_kwargs)

        # excel data is parsed correctly
        assert df.iloc[1][1] == "Harry Carney"

        # having diff tab counts doesn't trigger it
        text = dedent(
            """
            a\t b
            1  2
            3  4
            """.strip()
        )
        mock_clipboard[request.node.name] = text
        res = pd.read_clipboard(**clip_kwargs)

        text = dedent(
            """
            a  b
            1  2
            3  4
            """.strip()
        )
        mock_clipboard[request.node.name] = text
        exp = pd.read_clipboard(**clip_kwargs)

        tm.assert_frame_equal(res, exp)
Exemple #32
0
def get_clipboard():
    # 從 中央氣象局取得區域的月均溫
    # https://www.cwb.gov.tw/V8/C/C/Statistics/monthlymean.html

    # 因為取得的資料是一列的資料,透過 numpy 的 reshape ,轉換為正確的欄位
    data = pd.read_clipboard(header=None).values.reshape(-1, 16)
    # 整理取得的資料,並形成 csv 檔
    filename = "./Day21-30/data/climate.csv"
    # 新的資料最後 2 欄為平均溫的統計區間,因為用不到,所以就不儲至 csv 檔
    # 寫入 csv 檔的時候,不寫入 header 和 index ,所以 header=None, index=None
    pd.DataFrame(data[:, :-2]).to_csv(filename, header=None, index=None)
    tmp = data[:, :-2]
    climate_data = list(tmp)
    return climate_data
Exemple #33
0
def read_from_clipboard(date_columns='nan') -> 'DataFrame':
    """Using the Pandas framework, copy the table that is in the clipboard, into a data frame, and
    return that data frame. If the user provides a list of date column headers, Python will
    automatically (try to) interpret the dates in that column into datetime format."""

    # try:
    if date_columns == 'nan' or date_columns == '':
        clipboard_table = pd.read_clipboard()
    else:
        try:
            clipboard_table = pd.read_clipboard(parse_dates=date_columns, dayfirst=True)
        except:
            clipboard_table = pd.read_clipboard()
            print('Tried to parse dates, but the date_columns given may not exist.')

    if clipboard_table.size == 0 or clipboard_table.empty:
        clipboard_table = 'Clipboard is empty. Select an Excel table and try again.'
    else:
        print(clipboard_table.size, 'items imported from clipboard...')
    # except:
    #    clipboard_table = 'No clipboard contents found. Select an Excel table and try again.'

    return clipboard_table
Exemple #34
0
def export_trades():
    # Export trades from Nova and create csv for new trades

    # Check Nova is visible
    header_loc = pyautogui.locateCenterOnScreen(r'C:\Users\tdavies\PycharmProjects\untitled\matchID.png')
    if header_loc is None:
        return print("Can't find Match ID column header - make sure Nova blotter is visible")

    # Copy current Trade Book
    pyautogui.rightClick(header_loc)
    pyautogui.typewrite('c')
    pyautogui.press('enter')
    df_alltrades = pd.read_clipboard()

    # Compare export with previous export to identify new trades
    df_prevtrades = pd.read_csv('BBSW Prev Export.csv')
    df_newtrades = df_alltrades.copy()
    already_reg = ''
    for trade in df_alltrades.ID:
        if trade in df_prevtrades.ID.values:
            df_newtrades = df_newtrades[df_newtrades.ID != trade]
            #already_reg += (str(trade) + ' ')
    #print(str(already_reg) + ' already registered')

    # Write new trades to csv
    if not df_newtrades.empty:
        # Get run number and update run_count file
        df_runcount = pd.read_csv('run_count.csv')
        if df_runcount.Date[0] == str(datetime.date.today()):
            df_runcount.Run[0] += 1
        else:
            df_runcount.Date[0] = str(datetime.date.today())
            df_runcount.Run[0] = 1
        df_runcount.to_csv('run_count.csv', index=False)

        # Add seconds to the trade times
        df_newtrades['Exec. Date'] = df_newtrades['Exec. Date'] + ":" + str(datetime.datetime.now().second)

        # Write new trades to csv
        newtrades_filename = str(datetime.date.today()) + '-TPBBSW_' + str(df_runcount.Run[0]) + '.csv'
        df_newtrades.to_csv(newtrades_filename, index=False)
        df_alltrades.to_csv('BBSW Prev Export.csv', index=False)
        print(str(newtrades_filename) + ' successfully exported. ' + str(datetime.datetime.now()))

        #print('Sleeping for 5secs - ' + str(datetime.datetime.now()))
        #time.sleep(5)
        transfer_file(newtrades_filename)

    else:
        print('No new trades.')
def StockToolInterface(mStockData):
    try:
        dll = CDLL(
            'D:\\MyProjects\\win_project\\DataFrameTool\\x64\\Release\\DataFrameTool.dll'
        )
        mStockData.to_clipboard()
        b = dll.ToolInterface(1)
        result = pd.read_clipboard()
        win32api.FreeLibrary(dll._handle)
        return result
    except:
        print 'Error'
        win32api.FreeLibrary(dll._handle)
        return mStockData
Exemple #36
0
        def parse_clipboard(self):
            
            clip_board_df = pd.read_clipboard()
            
            if clip_board_df is None:
                return
                
            if len(clip_board_df.columns) < 2:
                return 
                
            for index in clip_board_df.index:
                self.add_clip_board_row(clip_board_df.ix[index])

            self.validatedPowerCurveLevels.validate()
Exemple #37
0
 def __init__(self, tablename="tmp_clipboard_del7", dev_mode=False, df=None):
     super(ClipToExa, self).__init__()
     self.tablename = tablename
     # TODO: the constructor is too dirty -> refactor (e.g. spaghetti to functions)
     # TODO: Assure that input data is clean enough (test dirty inputs)
     if dev_mode:
         self.dataframe = self.dev_data()
     elif isinstance(df, pd.DataFrame):
         self.dataframe = df
     else:
         self.dataframe = pd.read_clipboard()
     self.cols = [self.string_cleaner(c) for c in self.dataframe.columns]
     self.dataframe.columns = self.cols
     print("Initiated the following DataFrame:", self.dataframe.head(), sep="\n")
Exemple #38
0
    def parse_clipboard(self):

        clip_board_df = pd.read_clipboard()

        if clip_board_df is None:
            return

        if len(clip_board_df.columns) < 2:
            return

        for index in clip_board_df.index:
            self.add_clip_board_row(clip_board_df.ix[index])

        self.validatedPowerCurveLevels.validate()
Exemple #39
0
def unclip(*args, **kwargs):
    import pandas as pd
    df = pd.read_clipboard()
    data = decodes(df.columns[0])
    if 'blueprint' in data:
        label = data['blueprint']['label']
        filename = label.replace(' ', '_').lower()
        with open(f'blueprints/{filename}.json', 'w') as f:
            json.dump(data, f, indent=INDENT, sort_keys=False)
    elif 'blueprint_book' in data:
        label = data['blueprint_book']['label']
        filename = label.replace(' ', '_').lower()
        with open(f'books/{filename}.json', 'w') as f:
            json.dump(data, f, indent=INDENT, sort_keys=False)
Exemple #40
0
def paste(source='vertical'):
    ''' Convert a clipboard sourced list from text or excel file

    Examples
    --------
    columns = paste(source='text')

    Parameters
    ----------
    source
        Default 'vertical'
        vertical        - copy from a vertical list of values (usually Excel)
        horizontal      - copy from a horizontal list of values (usually Excel)
        horizontal_list - return a horizontal list

    Returns
    -------
    Clipboard contents
    '''

    if source == 'vertical':
        dx = pd.read_clipboard(header=None, names=['x'])

        # make sure no apostrophe's copied into clipboard contents by mistake
        # dx['x'] = dx['x'].str.replace("""["']""", '', regex=True)

        data = "['" + "', '".join(dx.x.astype(str).values.tolist()) + "']"

    if source == 'horizontal_list':
        dx = pd.read_clipboard(sep='\t')
        data = dx.columns.tolist()

    if source == 'horizontal':
        dx = pd.read_clipboard(sep='\t')
        data = "['" + "', '".join(dx.columns.tolist()) + "']"

    return data
Exemple #41
0
def clipboardToDict(sep):
    """ Parse two-column delimited clipboard contents to a dictionary.

    Parameters
    ----------
    sep : str
        A string or regex to use as delimiter.

    Returns
    -------
    A dictionary derived from clipboard contents.
    """
    df = pd.read_clipboard(sep, header=None, engine='python')
    d = {k: v for k, v in zip(df[0], df[1])}
    return d
Exemple #42
0
def inquire_commit(path):
    app = Application().connect(path=path)
    app[u"网上股票交易系统5.0"]["CVirtualGridCtrl"].click_input()
    SendKeys.SendKeys('R')
    SendKeys.SendKeys('{F5}')
    time_wait.sleep(0.5)
    app[u"网上股票交易系统5.0"]["CVirtualGridCtrl"].TypeKeys('^c')
    try:
        data = pd.read_clipboard()
        day = str(datetime.now().date())
        time = [pd.to_datetime(day + " " + i) for i in data["委托时间"]]
        data.index = time
        return data
    except:
        return None
Exemple #43
0
 def do_paste(self, event):
     """
     Read clipboard into dataframe
     Paste data into grid, adding extra rows if needed
     and ignoring extra columns.
     """
     # find where the user has clicked
     col_ind = self.GetGridCursorCol()
     row_ind = self.GetGridCursorRow()
     # read in clipboard text
     text_df = pd.read_clipboard(header=None, sep='\t').fillna('')
     # add extra rows if need to accomadate clipboard text
     row_length_diff = len(text_df) - (len(self.row_labels) - row_ind)
     if row_length_diff > 0:
         for n in range(row_length_diff):
             self.add_row()
     # ignore excess columns if present
     col_length_diff = len(text_df.columns) - (len(self.col_labels) - col_ind)
     #print "len(text_df.columns) -  (len(self.col_labels) - col_ind)"
     #print len(text_df.columns), " - ", "(", len(self.col_labels), "-", col_ind, ")"
     #print 'col_length_diff', col_length_diff
     if col_length_diff > 0:
         text_df = text_df.iloc[:, :-col_length_diff].copy()
     # go through copied text and parse it into the grid rows
     for label, row_data in text_df.iterrows():
         col_range = list(range(col_ind, col_ind + len(row_data)))
         if len(row_data) > 1:
             cols = list(zip(col_range, row_data.index))
             for column in cols:
                 value = row_data[column[1]]
                 this_col = column[0]
                 self.SetCellValue(row_ind, this_col, str(value))
         else:
             value = row_data[0]
             self.SetCellValue(row_ind, col_ind, str(value))
         row_ind += 1
     # could instead use wxPython clipboard here
     # see old git history for that
     self.size_grid()
     event.Skip()
Exemple #44
0
    def read_clipboard(self):

        # def _en_col(s):
            # import re
            # _res = re.findall(r'[\-\+\d\.]+', s)
            # self.X = mesh1d([float(a) for (i, a)
                             # in enumerate(_res) if not i % 2],
                            # self.X.label, self.X.unit)
            # self.Y = mesh1d([float(a) for (i, a) in enumerate(_res) if i % 2],
                            # self.Y.label, self.Y.unit)
            # self._set_size()

        # def _en_ligne(s):
        #    En colonne
            # s = s.split('\r\n')
            # if len(s) == 2:
                # self.X = mesh1d([float(a) for a in s[0].split('\t')],
                                # self.X.label, self.X.unit)
                # self.Y = mesh1d([float(a) for a in s[1].split('\t')],
                                # self.Y.label, self.Y.unit)
                # self._set_size()
        import pandas as pd
        s = pd.read_clipboard(index_col=0, decimal=",")
        self.from_pandas(s)
Exemple #45
0
 def read_clipboard(self):
     clip_data = pd.read_clipboard()
     return clip_data
Exemple #46
0
#print( pd.concat([ww2_cas,obj2]).sort_index(inplace=True) ) 
# inplace = True  --> modifica realmente la serie !!
# il problema è che non posso richiamarla perchè non l'ho instanziata: ho usato metodi all'interno del metodo print()

s3 = pd.concat([ww2_cas,obj2]).sort_index(inplace=True)
print( s3 )

#add a name to a Serie or index
s3.name = 'World War 2 Casualties'
s3.index.name = 'Countries'
print( '\n', s3 )

#******************************************************************************
#******************************************************************************
#    DATAFRAMES
#******************************************************************************
from Singleton_Path import *                                            # Singleton usato per definire Variabili Globali  


#Add some data for Exemple
#import webbrowser as wb
#website = 'http://en.wikipedia.org/wiki/NFL_win-loss_records'
#wb.open(website)


#Copy and read to get data..then showing
nfl_frame = pd.read_clipboard()         # Devo copiare dalla ClipBoard !! return Series
nfl_frame.to_csv(str(Path.Instance()) + 'nfl_frame.csv')


Exemple #47
0
import sys; import os; sys.path.append(os.path.expanduser('~/DropBox/my/projects/python/'))
import pandas as pd
import stats as stats
import datetime as datetime
import datedimension as dim
import numberformatter as form
import download as download
import matplotlib.pyplot as mat
import wcloud as wcloud

import seaborn as sns
sns.set_style("whitegrid")

# clipboard -> data frame
data = pd.read_clipboard()

data
data.describe()


# HISTOGRAM
# http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.hist.html
plt = data.hist()
plt = data.hist(bins=100)


# BOX PLOT
plt = sns.boxplot(x="type", y="value", data=data[-100:])
plt.set(title="My Box plot")
Exemple #48
0
 def check_round_trip_frame(self, data_type):
     data = self.data[data_type]
     data.to_clipboard()
     result = read_clipboard()
     tm.assert_frame_equal(data, result, check_dtype=False)
 def test_round_trip_frame_string(self, df):
     df.to_clipboard(excel=False, sep=None)
     result = read_clipboard()
     assert df.to_string() == result.to_string()
     assert df.shape == result.shape
 def check_round_trip_frame(self, data, excel=None, sep=None,
                            encoding=None):
     data.to_clipboard(excel=excel, sep=sep, encoding=encoding)
     result = read_clipboard(sep=sep or '\t', index_col=0,
                             encoding=encoding)
     tm.assert_frame_equal(data, result, check_dtype=False)
 def test_invalid_encoding(self, df):
     # test case for testing invalid encoding
     with pytest.raises(ValueError):
         df.to_clipboard(encoding='ascii')
     with pytest.raises(NotImplementedError):
         pd.read_clipboard(encoding='ascii')
Exemple #52
0
       This will import the data into a Pandas DataFrame. If the header row
       is also copied into clipboard, it will be the name of the dataframe column
       with the data.
    4. Plot them using pyplot by selecting the columns you want plotted.

To import data from Orcaflex, just extract data as values and copy it.

This script is not supposed to be run. Import from clipboard should be executed
line by line.

Created on Fri Nov  3 08:13:17 2017
@author: rarossi
"""
# %%
import pandas as pd
from matplotlib import pyplot as plt

# %%
input('Copy data to clipboard and press any key\n')
correct = pd.read_clipboard()

input('Copy data to clipboard and press any key\n')
wrong = pd.read_clipboard()

# %%
plt.plot(correct.Time, correct.Tension, label='correct')
plt.plot(wrong.Time, wrong.Tension, label='wrong')

plt.grid()
plt.legend(loc='best')
 def test_clipboard_copy_strings(self, sep, excel, df):
     kwargs = build_kwargs(sep, excel)
     df.to_clipboard(**kwargs)
     result = read_clipboard(sep=r'\s+')
     assert result.to_string() == df.to_string()
     assert df.shape == result.shape
# Lecture 15 - DataFrame

import numpy as np
import pandas as pd

from pandas import Series,DataFrame

import webbrowser

website = 'http://en.wikipedia.org/wiki/NFL_win-loss_records'
webbrowser.open(website)

nfl_frame = pd.read_clipboard() # copy a table and read from clipboard
nfl_frame

nfl_frame.columns # column names

# select a column
nfl_frame.Team
nfl_frame['Team']
nfl_frame['First NFL Season']

# select multiple columns
DataFrame(nfl_frame, columns=['Team', 'First NFL Season', 'Total Games'])

# included column that doesn't exist: creates a null column
DataFrame(nfl_frame, columns=['Team', 'First NFL Season', 'Total Games', 'Stadium'])

# selecting rows
nfl_frame.head() # return first five rows
nfl_frame.head(3) # return first 3 rows
Exemple #55
0
def getTable():
    return pd.read_clipboard(header = None, sep=r"\t")
"""
  Name     : 4375OS_08_04_read_clipboard.py
  Book     : Python for Finance
  Publisher: Packt Publishing Ltd. 
  Author   : Yuxing Yan
  Date     : 12/26/2013
  email    : [email protected]
             [email protected]
"""

import pandas as pd
x=pd.read_clipboard()
###															###
###															###
###   				DataFrame basics						###
###															###
###															###
###############################################################

# the key method here is DataFrame()

import webbrowser
website = 'https://en.wikipedia.org/wiki/NFL_win%E2%80%93loss_records'
webbrowser.open(website)

# open the browser and copy the data frame on your clipboard

nfl_frame = pd.read_clipboard() # copy clipboard into a dataframe

nfl_frame.columns # column names
nfl_teams = nfl_frame['Team'] # extract data from column 'Team'. This data is now a series.
nfl_teams_list = nfl_teams.tolist() # convert the series into a list

DataFrame(nfl_frame,columns = ['Team', 'First Season','Total Games']) #subset only the required columns

nfl_frame.head(3) # return top 3 rows
nfl_frame.tail(4) # return bottom 4 rows

nfl_frame.ix[3] # returns object for index 3 using .ix

nfl_frame['Stadium'] = "Levi's Stadium" # returns subset of rows where column = "Levi's Stadium"

nfl_frame['Stadium'] = np.arange(1,6) # replace values in a columns
import numpy as np
import pandas as pd

#Read the top 250 from IMDb from the clipboard
top250 = pd.read_clipboard()

#Drop columns with no useful information
top250.dropna(axis=1, inplace=True)
top250.columns = ['TitleYear','Rating']

#Fix the title, now it has the index, title and year together
theindex = [int(i.split('.',1)[0]) for i in top250.TitleYear]
thetitle_year = [i.split('.',1)[1].strip() for i in top250.TitleYear]
thetitle = [i.rsplit('(',1)[0].strip() for i in thetitle_year]
theyear = [int(i.rsplit('(',1)[1].rstrip(')')) for i in thetitle_year]

#Add title, year and position on the top 250 list
top250['Title'] = pd.Series(thetitle, index=top250.index)
top250['Year'] = pd.Series(theyear, index=top250.index)
top250['Nr'] = pd.Series(theindex, index=top250.index)

#Set position as the index for the DataFrame
top250.set_index('Nr', inplace=True)

#Drop the old title, the new one is much better
top250.drop('TitleYear', axis=1, inplace=True)

#Reorder the columns so that the rating is the last column.
cols = top250.columns
top250 = top250.reindex_axis(list(top250.columns[1:]) + ['Rating'], axis=1)
### 1. Data frame
import numpy as npy
import pandas as pd
from pandas import Series, DataFrame

# Create a data frame using data on a website
import webbrowser
website = 'http://en.wikipedia.org/wiki/NFL_win-loss_records'
webbrowser.open(website)
nfl_frame = pd.read_clipboard()
nfl_frame

# Explore the data frame
nfl_frame.columns
nfl_frame.Team
nfl_frame['First NFL Season']
DataFrame(nfl_frame,columns=['Team','First NFL Season','Total Games','Stadium'])
nfl_frame.head(3)
nfl_frame.ix[3]

# Add new columns to an existing data frame
nfl_frame['Stadium'] = np.arrange(5)
stadiums = Series(["Levi's Stadium","AT&T Stadium"],index=[4,0])
nfl_frame['Stadium']=stadiums
del nfl_frame['Stadium']

# Create data frames from dictionaries
data = {'City':['SF','LA','NYC'],'Population':[837000,388000,840000]}
city_frame = DataFrame(data)

# Reindex