當前位置: 首頁>>代碼示例>>Python>>正文


Python DataFrame.append方法代碼示例

本文整理匯總了Python中pandas.core.frame.DataFrame.append方法的典型用法代碼示例。如果您正苦於以下問題:Python DataFrame.append方法的具體用法?Python DataFrame.append怎麽用?Python DataFrame.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.frame.DataFrame的用法示例。


在下文中一共展示了DataFrame.append方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: lookup_last_week_weather

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
def lookup_last_week_weather(look_str, weatherDF, weather_station=1):
    now = datetime.strptime(look_str, "%Y-%m-%d")
    weathers = DataFrame()
    for i in range(35):
        one_day = timedelta(days=i)
        now1 = now - one_day
        row = weatherDF[(weatherDF.Date == now1.strftime("%Y-%m-%d")) & (weatherDF.Station == weather_station)]
        weathers = weathers.append(row)
    return weathers
開發者ID:juandoso,項目名稱:Competitions,代碼行數:11,代碼來源:utils.py

示例2: ReadStandardData

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
 def ReadStandardData(file_name):
     Data=DataFrame({})
     f=open(file_name,'r')
     while True:
         new_line=standard_form_data._AnalyseStandardLine(f.readline())
         if type(new_line) is DataFrame:
             Data=Data.append(new_line,ignore_index=True)
         elif new_line == '#':
             continue
         elif new_line==None:
             break
     f.close()
     return Data
開發者ID:vooum,項目名稱:ScanCommander,代碼行數:15,代碼來源:ReadData.py

示例3: run

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
 def run(self):
     self.sem.acquire()
     while datetime.now() < self.timeout:
         try:
             # Randomy length dataframe to keep appending to
             df = DataFrame({'v': [self.last]}, [datetime.now()])
             for i in range(random.randint(1, 10)):
                 df = df.append(DataFrame({'v': [self.last + i]}, [datetime.now()]))
             self.last + i
             df.index.name = 'index'
             self.lib.append('symbol', df)
             assert self.last in self.lib.read('symbol').data['v'].tolist()
             self.last += 2
         except OptimisticLockException:
             # Concurrent write, not successful
             pass
開發者ID:manahl,項目名稱:arctic,代碼行數:18,代碼來源:test_concurrent_append.py

示例4: average_csv_data

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
def average_csv_data(patients, filename, target, *data_path):
    data_path = data_path[0]
    df_list = []
    for p in data_path:
        df = DataFrame(columns=['clip',target])
        for patient in patients:
            d = read_csv(p + '/' + patient + target + '.csv')
            df = df.append(d)
        df_list.append(df)

    avg_df = DataFrame(columns=['clip', target])
    avg_df['clip'] = df_list[0]['clip']
    avg_df[target] = 0
    for df in df_list:
        avg_df[target] += df[target]

    avg_df[target] /= 1.0 * len(df_list)

    with open(filename+'.csv', 'wb') as f:
        avg_df.to_csv(f, header=True, index=False)
開發者ID:IraKorshunova,項目名稱:kaggle-seizure-detection,代碼行數:22,代碼來源:avg_patients.py

示例5: enumerate

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
Data=DataFrame({})
for ith,document in enumerate(input_list):
    if ith%100==0:
        print('recording %ith, total %i'%(ith,total))

    spectr=ReadNMSSMToolsSpectr(document,ignore=ignore)
    # inNumber=re.findall(r'\d+',document)[-1]
    # outNumber+=1   # reNumber

    col_name=['No_','path']
    value_row=[ith,document]

    for block,code_value_dict in spectr.__dict__.items():
        # print(block_name)
        try:
            code_2_name=getattr(block_table,block)
        except AttributeError:
            continue
        else:
            for code,value in code_value_dict.items():
                try:
                    col_name.append(code_2_name(code))
                except KeyError:
                    raise# continue
                else:
                    value_row.append(value)
    Data=Data.append(
        DataFrame(numpy.array([value_row]),columns=col_name),
        ignore_index=True)

Data.to_csv('Data_%s.csv'%similarity)
開發者ID:vooum,項目名稱:ScanCommander,代碼行數:33,代碼來源:gather_NTs.py

示例6: tee

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
from makstat.zavod import iter_contextual_atom_data, get_metadata


stream = (line.decode('cp1251').strip().encode('utf-8')
          for line in stdin)

# tee the stream to get the metadata for title
stream, stream_2 = tee(stream)

title = get_metadata(stream_2)['TITLE']

df = DataFrame()
for cur_data in iter_contextual_atom_data(stream):
    current = DataFrame.from_dict([cur_data])
    df = df.append(current, ignore_index=False)

index_cols = list(df.columns.values)
index_cols.remove('value')
df.set_index(index_cols, inplace=True)
df.columns = [title]

# create removable temp file for use with HDFStore
tmpfile = NamedTemporaryFile().name

store = HDFStore(tmpfile)
store['default'] = df
store.close()

# put h5 file to stdout
with open(tmpfile, 'rb') as f:
開發者ID:petrushev,項目名稱:makstat,代碼行數:32,代碼來源:px2h5.py

示例7: _h_index

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
    def _h_index(self):

        K = self.model.K
        topic_counts = {}

        for i in range(K):

            sys.stdout.flush()

            # find the words in this topic above the threshold
            topic_words = self.topicdf.ix[:, i]
            topic_words = topic_words.iloc[topic_words.nonzero()[0]]

            fragment_words = {}
            loss_words = {}
            for word in topic_words.index:
                tokens = word.split('_')
                word_type = tokens[0]
                value = tokens[1]
                if word_type == 'fragment':
                    fragment_words[value] = 0
                elif word_type == 'loss':
                    loss_words[value] = 0

            # find the documents in this topic above the threshold
            topic_docs = self.docdf.ix[i, :]
            topic_docs = topic_docs.iloc[topic_docs.nonzero()[0]]

            # handle empty topics
            if topic_docs.empty:

                topic_counts[i] = 0

            else:

                # now find out how many of the documents in this topic actually 'cite' the words
                for docname in topic_docs.index:

                    # split mz_rt_peakid string into tokens
                    tokens = docname.split('_')
                    peakid = int(tokens[2])

                    # find all the fragment peaks of this parent peak
                    ms2_rows = self.ms2.loc[self.ms2['MSnParentPeakID']==peakid]
                    fragment_bin_ids = ms2_rows[['fragment_bin_id']]
                    loss_bin_ids = ms2_rows[['loss_bin_id']]

                    # convert from pandas dataframes to list
                    fragment_bin_ids = fragment_bin_ids.values.ravel().tolist()
                    loss_bin_ids = loss_bin_ids.values.ravel().tolist()

                    # this code is too slow!
                    # count the citation numbers
#                     for cited in fragment_bin_ids:
#                         if cited == 'nan':
#                             continue
#                         else:
#                             if cited in fragment_words:
#                                 fragment_words[cited] = fragment_words[cited] + 1
#                     for cited in loss_bin_ids:
#                         if cited == 'nan':
#                             continue
#                         else:
#                             if cited in loss_words:
#                                 loss_words[cited] = loss_words[cited] + 1

                    # convert to dictionary for quick lookup
                    word_dict = {}
                    for word in fragment_bin_ids:
                        word_dict.update({word:word})
                    for word in loss_bin_ids:
                        word_dict.update({word:word})

                    # count the citation numbers
                    for word in fragment_words:
                        if word in word_dict:
                            fragment_words[word] = fragment_words[word] + 1
                    for word in loss_words:
                        if word in word_dict:
                            loss_words[word] = loss_words[word] + 1

                    # make a dataframe of the articles & citation counts
                    fragment_df = DataFrame(fragment_words, index=['counts']).transpose()
                    loss_df = DataFrame(loss_words, index=['counts']).transpose()
                    df = fragment_df.append(loss_df)
                    df = df.sort(['counts'], ascending=False)

                    # compute the h-index
                    h_index = 0
                    for index, row in df.iterrows():
                        if row['counts'] > h_index:
                            h_index += 1
                        else:
                            break

                print " - Mass2Motif " + str(i) + " h-index = " + str(h_index)
                topic_counts[i] = h_index

        return topic_counts
開發者ID:sdrogers,項目名稱:MS2LDA,代碼行數:101,代碼來源:lda_for_fragments_viz.py

示例8: _h_index

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
 def _h_index(self):
             
     topic_counts = {}
     n_topics = self.model.K
     for i in range(n_topics):
         
         sys.stdout.flush()
         
         # find the words in this topic above the threshold
         fragment_words = self._get_nonzero_words(i, self.topicdfs, 0)
         loss_words = self._get_nonzero_words(i, self.topicdfs, 1)
         
         # find the documents in this topic above the threshold
         topic_docs = self.docdf.ix[i, :]
         topic_docs = topic_docs.iloc[topic_docs.nonzero()[0]]
         
         # handle empty topics
         if topic_docs.empty:
             
             topic_counts[i] = 0
             
         else:
         
             # now find out how many of the documents in this topic actually 'cite' the words    
             for docname in topic_docs.index:
 
                 # split mz_rt_peakid string into tokens
                 tokens = docname.split('_')
                 peakid = int(tokens[2])
                 
                 # find all the fragment peaks of this parent peak
                 ms2_rows = self.ms2.loc[self.ms2['MSnParentPeakID']==peakid]
                 fragment_bin_ids = ms2_rows[['fragment_bin_id']]
                 loss_bin_ids = ms2_rows[['loss_bin_id']]       
                 
                 # convert from pandas dataframes to list
                 fragment_bin_ids = fragment_bin_ids.values.ravel().tolist()
                 loss_bin_ids = loss_bin_ids.values.ravel().tolist()
                 
                 # count the citation numbers
                 for cited in fragment_bin_ids:
                     if cited == 'nan':
                         continue
                     else:
                         if cited in fragment_words:
                             fragment_words[cited] = fragment_words[cited] + 1
                 for cited in loss_bin_ids:
                     if cited == 'nan':
                         continue
                     else:
                         if cited in loss_words:
                             loss_words[cited] = loss_words[cited] + 1
                 
                 # make a dataframe of the articles & citation counts
                 fragment_df = DataFrame(fragment_words, index=['counts']).transpose()
                 loss_df = DataFrame(loss_words, index=['counts']).transpose()
                 df = fragment_df.append(loss_df)
                 df = df.sort(['counts'], ascending=False)
                 
                 # compute the h-index
                 h_index = 0
                 for index, row in df.iterrows():
                     if row['counts'] > h_index:
                         h_index += 1
                     else:
                         break
 
             topic_counts[i] = h_index
         
     return topic_counts
開發者ID:sdrogers,項目名稱:MS2LDA,代碼行數:72,代碼來源:lda_3bags_for_fragments_viz.py

示例9: DataFrame

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
repos_with_kw_docker_2015_filepath = data_files_path + \
    'repos_with_docker_2015.csv'


df_github_repos_with_kw_docker_2011_to_2014 = DataFrame(pandas.read_csv(
    repos_with_kw_docker_2011_to_2014_filepath
)['repository_url'])


def apiurl_to_repourl(apiurl):
    return apiurl.replace('api.', '').replace('repos/', '')

df_repos_2015 = pandas.read_csv(repos_with_kw_docker_2015_filepath)['repo_url']
df_github_repos_with_kw_docker_2015 = DataFrame({
    'repository_url': map(apiurl_to_repourl, df_repos_2015)
})

df_repo_urls_with_kw_docker_2011_to_2015 = \
    df_github_repos_with_kw_docker_2011_to_2014.append(
        df_github_repos_with_kw_docker_2015,
        ignore_index=True
    )


def make_test_dataset(**kwargs):
    samplesize = kwargs['sample_size']
    testdf = df_repo_urls_with_kw_docker_2011_to_2015[:samplesize]
    # print testdf['repository_url'].drop_duplicates().values.tolist()
    return testdf['repository_url'].drop_duplicates().values.tolist()
開發者ID:pombredanne,項目名稱:githubscrape,代碼行數:31,代碼來源:github_docker_urls.py

示例10: weather_data

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import append [as 別名]
        now1 = now - one_day
        row = weatherDF[(weatherDF.Date == now1.strftime("%Y-%m-%d")) & (weatherDF.Station == weather_station)]
        weathers = weathers.append(row)
    return weathers

def weather_data(look_str, weatherDF):
    features = ["Tmax","Tmin","Tavg","DewPoint", "WetBulb", "Heat","Cool","SnowFall", "PrecipTotal", "ResultSpeed"]
    weather_week0 = lookup_last_week_weather(look_str, weatherDF)
    weather_week = weather_week0[features]
    averagesS = weather_week.mean(0)
    maxs = weather_week.max(0)
    maxsS = pd.Series()
    mins = weather_week.min(0)
    minsS = pd.Series()
    for f in features:
        maxsS["%s_max" % f] = maxs[f]
        minsS["%s_min" % f] = mins[f]
    #datapoints = pd.concat([averagesS, maxsS, minsS])
    datapoints = averagesS
    weather_data = DataFrame(datapoints).T
    weather_data["Date"] = look_str
    return weather_data
        
weather_avg = DataFrame()
dates = weather["Date"]
for d in dates:
    row = weather_data(d, weather)
    weather_avg= weather_avg.append(row, ignore_index=True)
weather_avg.to_csv(os.path.join(data_dir,'weather_info_averages5.csv'), index=False)

# duplicates()
開發者ID:juandoso,項目名稱:Competitions,代碼行數:33,代碼來源:utils.py


注:本文中的pandas.core.frame.DataFrame.append方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。