DataFramesλ₯Ό μ°κ²°ν λ μ΄ μ΄λ¦ κ°μ μ°¨μ΄μ μ΄ μμΌλ©΄ μ΄ μ΄λ¦μ΄ μμ«μ μμΌλ‘ μ λ ¬
μ΄ μ’
λ₯λ λ¬Έμνλμ§ μμμΌλ©° μνμ§ μμ΅λλ€. νμ€ν κΈ°λ³Έ λμμ μ λ ¬λμ§ μμμΌ ν©λλ€. νΈμ§: SQLμμμ κ°μ νμ€ μμλ λ€μκ³Ό κ°μ΅λλ€. df1μ μ΄(df1κ³Ό λμΌν μμ), df2μ μ΄(κ³ μ νκ²)(κ³΅ν΅ μ΄μ΄ μ μ)(df2μ λμΌν μμ). μμ:
df4a = DataFrame(columns=['C','B','D','A'], data=np.random.randn(3,4))
df4b = DataFrame(columns=['C','B','D','A'], data=np.random.randn(3,4))
df5 = DataFrame(columns=['C','B','E','D','A'], data=np.random.randn(3,5))
print "Cols unsorted:", concat([df4a,df4b])
# Cols unsorted: C B D A
print "Cols sorted", concat([df4a,df5])
# Cols sorted A B C D E
``'
μ΄κ²μ κ°λ¨ν _μκ°_ νλ©΄ λ μ€νΈλ§μ΄ λ€μκ³Ό κ°μ΄ λͺ μλμ΄ μλ Index.intersectionμμ μ λν©λλ€.
λ μΈλ±μ€ κ°μ²΄μ κ΅μ°¨λ₯Ό νμ±ν©λλ€. κ²°κ³Όμ μ λ ¬μ΄ λ³΄μ₯λμ§ μμ΅λλ€.
μ΄λ€ κ²½μ°μ νμ/μ λ ¬λλμ§ νμ€νμ§ μμ§λ§ μ΄μ΄ λμΌν κ²½μ°(첫 λ²μ§Έ μ΄μμ)λ λμΌν κ²°κ³Όλ₯Ό λ°ννλ νΉμν κ²½μ°μ λλ€...
@smcierney λμ μ΄λ€ μμλ₯Ό κΈ°λνμκ² μ΅λκΉ?
λλ 루νμ λΉ νλ μμ νλ μμ μ°κ²°νλ €κ³ μλνκΈ° λλ¬Έμ(μ: λͺ©λ‘μ μμ μΆκ°) μλ μ λ ¬μ΄ μ½κ° μ±κ°μλ€λ κ²μ μμμ΅λλ€. κ·Έλ° λ€μ μ΄ μμκ° λ³κ²½λμμμ κΉ¨λ¬μμ΅λλ€. μΆ=1μ λ°λΌ μ°κ²°νλ κ²½μ° μ΄ λ³κ²½ μ¬νμ μΈλ±μ€μλ μ μ©λ©λλ€.
@smcinerney μ κ²½μ°μ μ μ¬ν κ²½μ°
λ°λΌμ λλ "hack"μ μΌμ΅λλ€ (μ’ λ°λ³΄ κ°μ§λ§)
sorted = pd.concat(frameList, axis=axis, join=join, join_axes=join_axes, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False)
if join_axes:
return sorted
elif sort:
return sorted
else:
# expand all original orders in each frame
sourceOrder = []
for frame in frameList:
sourceOrder.extend(frame.Columns()) if axis == 0 else sourceOrder.extend(frame.Indices())
sortedOrder = sorted.Columns() if axis == 0 else sorted.Indices()
positions = []
positionsSorted = []
for i in sortedOrder:
positions.append(sourceOrder.index(i))
positionsSorted.append(sourceOrder.index(i))
positionsSorted.sort()
unsortedOrder = []
for i in positionsSorted:
unsortedOrder.append(sortedOrder[positions.index(i)])
return sorted.ReorderCols(unsortedOrder) if axis == 0 else sorted.ReorderRows(unsortedOrder)
μ΄ κΈ°λ₯μ kungfu!λΌλ κ°μΈ λͺ¨λμ ν¬ν¨λμ΄ μμ΅λλ€. λꡬλ μμ μκ³ λ¦¬μ¦μ μ±ννκ±°λ https://github.com/jerryzhujian9/kungfu μμ λ΄ λͺ¨λμ λ³Ό μ
λ§μ§λ§μΌλ‘ μ΄ νλ₯ν λͺ¨λμ λν κ°λ° νμ λ Έκ³ μ κΉμ κ°μ¬λ₯Ό λ립λλ€!
μ΄ λμμ μ€μ λ‘ λ§€μ° μμμΉ λͺ»ν κ²μ΄λ©° μ λ μ°μ°ν λ°κ²¬νμ΅λλ€.
>>> df = pd.DataFrame()
>>> df['b'] = [1,2,3]
>>> df['c'] = [1,2,3]
>>> df['a'] = [1,2,3]
>>> print(df)
b c a
0 1 1 1
1 2 2 2
2 3 3 3
[3 rows x 3 columns]
>>> df2 = pd.DataFrame({'a':[4,5]})
>>> df3 = pd.concat([df, df2])
μμ§νκ²λ μ΄μ μμκ° μ μ§λ κ²μΌλ‘ μμν μ μμ΅λλ€. λμ μ΄μ΄ μ λ ¬λ©λλ€.
>>> print(df3)
a b c
0 1 1 1
1 2 2 2
2 3 3 3
0 4 NaN NaN
1 5 NaN NaN
[5 rows x 3 columns]
μ΄κ²μ λ€μκ³Ό κ°μ΄ μλ μ΄μ λ€μ μμΈννμ¬ μμ ν μ μμ΅λλ€.
>>> df4 = df3.reindex_axis(df.columns, axis=1)
>>> print(df4)
b c a
0 1 1 1
1 2 2 2
2 3 3 3
0 NaN NaN 4
1 NaN NaN 5
[5 rows x 3 columns]
μ¬μ ν μ΄ μλ μ λ ¬μ΄ μνλκ³ λ΄κ° μλ ν λΉνμ±νν μ μλ€λ κ²μ΄ μ§κ΄μ μ΄μ§ μμ κ² κ°μ΅λλ€.
λλ λ°©κΈ μ΄κ²μ μ νλ€.
new_data = pd.concat([churn_data, numerical_data])
DataFrame μμ±:
churn Var1 Var10 Var100 Var101
0 -1 NaN NaN NaN NaN
1 -1 NaN NaN NaN NaN
μ«μ DataFrameμ΄ λ¨Όμ μ λ ¬λμ§ μκ³ μ°κ²°λλ κ²μ΄ λ μμ°μ€λ¬μ λ³΄μΌ κ²μ λλ€!!
κΈμ, μ΄κ²μ μμ ν΄μΌ ν μ½κ°μ μμ μ λλ€. νμ§λ§ ν 리νμ€νΈκ° νμ©λ©λλ€!
DataFrames
μ°κ²°ν λ μ΄μ λμΌν λ¬Έμ κ° λ°μνμ΅λλ€. μ΄ λ¬Έμ μ λν΄ λͺ¨λ₯΄λ κ²½μ° μ½κ° μ±κ°μμ§λ§ μ€μ λ‘ λΉ λ₯Έ ν΄κ²° λ°©λ²μ΄ μμ΅λλ€.
dfs
μ΄ μ°κ²°νλ €λ DataFrames
μ λͺ©λ‘μ΄λΌκ³ κ°μ νλ©΄ μλ μ΄ μμλ₯Ό κ°μ Έμμ λ€μ μ
λ ₯ν μ μμ΅λλ€.
df = pd.concat(dfs, axis=0)
df = df[dfs[0].columns]
μ°Έκ³ λ‘ append
κ° λμΌν λμμ μ λ°νλ€κ³ μκ°ν©λλ€.
μ΄λ μ λ°μ μΌλ‘ κΈ°λ³Έ λμμ λλ€. μλ₯Ό λ€μ΄, ν¨μ fλ₯Ό λ€μν μμ μ΄μ λ°ννλ groupby()μ μ μ©νλ©΄ μ₯λ©΄ λ€μμ λ°μνλ μ°κ²°λ μ΄μ μλ μ λ ¬ν©λλ€.
df.groupby(some_ts).apply(f)
μ΄μ μλ €μ§ μμκ° ν΄μλ μ μκΈ° λλ¬ΈμΌ μ μμ΅λλ€.
κ·Έλ¬λ μ΄κ²μ MultiIndices λ° MultiIndicesμ λͺ¨λ κ³μΈ΅μμλ λ°μν©λλ€. λ°λΌμ level0 μ΄κ³Ό λͺ¨λ λ§λκ° νλμ level1 μ΄μ μΌμΉνλ λ°μ΄ν° νλ μμ μ°κ²°ν μ μμΌλ©° MultiIndicesμ λͺ¨λ μμ€μ νλμ level0 μ΄ λ΄μμ νλμ λΆμΌμΉλ‘ μΈν΄ μλ μ λ ¬λ©λλ€. λλ κ·Έκ²μ΄ λ°λμ§νλ€κ³ μκ°νμ§ μμ΅λλ€.
λμλλ¦¬κ³ μΆμ§λ§ λΆννλ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νλ κ²μ μ λ₯λ ₯ λ°μ λλ€. λͺ¨λλ€ λ Έκ³ μ κ°μ¬λ립λλ€.
μ΄ κΈ°λ₯μ λν΄ +1
λμν©λλ€, +1. μκΈ°μΉ μμ μ λ ¬μ΄ νμ λ°μν©λλ€.
+1, μ΄κ²μ λΆμΎν λλΌμμ΄μμ΅λλ€!
+1, λλ append
λ€μμ μ΄μ μ λ ¬νλ κ²μ μ«μ΄ν©λλ€.
λμκ²λ +1.
μ°κ²° νμ μλμΌλ‘ μ¬μ λ ¬νκ³ μΆμλλΌλ λ΄ λ°μ΄ν° νλ μμμ 60κ° μ΄μμ μ΄ μ΄λ¦κ³Ό μμΉλ₯Ό μΈμνλ €κ³ ν λ:
for id, value in enumerate(df.columns):
print id, value
60κ° μ΄μμ λͺ¨λ μ΄μ λ°μ΄ν° νλ μμμμ μ€μ μμΉκ° μλλΌ μνλ²³ μμλ‘ μΆλ ₯λ©λλ€.
μ¦, μ°κ²° ν μ¬μ λ ¬νλ €λ©΄ 60κ° μ΄ λͺ©λ‘μ μλμΌλ‘ μ λ ₯ν΄μΌ ν©λλ€. μμΌ.
λ΄κ° μ¬κΈ°μ μλ λμ λ΄κ° λλ½λ μ΄ μ΄λ¦κ³Ό μμΉλ₯Ό μΈμν μ μλ μ¬λμ΄ μμ΅λκΉ?
μ΄ κΈ°λ₯μ λν΄ +1, λ°©κΈ λμΌν κ±°λλ₯Ό λ§λ¬μ΅λλ€.
@summerela μ΄ μΈλ±μ€λ₯Ό κ°μ Έμ¨ λ€μ μλ μ΄ μΈλ±μ€λ₯Ό μ¬μ©νμ¬ μ λ°μ΄ν° νλ μμ λ€μ μΈλ±μ±ν©λλ€.
# assuming you have two dataframes, `df_train` & `df_test` (with the same columns)
# that you want to concatenate
# get the columns from one of them
all_columns = df_train.columns
# concatenate them
df_concat = pd.concat([df_train,
df_test])
# finally, re-index the new dataframe using the original column index
df_concat = df_concat.ix[:, all_columns]
λ°λλ‘, μ΄μ λ μμ νμ μ§ν©μ λ€μ μΈλ±μ±ν΄μΌ νλ κ²½μ° λ΄κ° λ§λ μ΄ ν¨μλ₯Ό μ¬μ©ν μ μμ΅λλ€. μλ μΈλ±μ€λ‘λ μλν μ μμ΅λλ€. μλ₯Ό λ€μ΄ μ΄μ λ°μ΄ν° νλ μμ λμΌλ‘ μ΄λνκ³ μΆμ§λ§ μ€ν¬λ¦½νΈμ μ΄μ μ²λ¦¬ λ¨κ³ νμ λ¨μ μλ μ΄μ μκ° νμ€νμ§ μμ κ²½μ°(μ: λΆμ°μ΄ μλ μ΄μ μμ νλ κ²½μ°) μλ μΈλ±μ€ μμΉλ₯Ό new_indices
--> new_indices = [-1]
μ λ¬ν μ μμΌλ©° λλ¨Έμ§λ μμμ μ²λ¦¬ν©λλ€.
def reindex_columns(dframe=None, columns=None, new_indices=None):
"""
Reorders the columns of a dataframe as specified by
`reorder_indices`. Values of `columns` should align with their
respective values in `new_indices`.
`dframe`: pandas dataframe.
`columns`: list,pandas.core.index.Index, or numpy array; columns to
reindex.
`reorder_indices`: list of integers or numpy array; indices
corresponding to where each column should be inserted during
re-indexing.
"""
print("Re-indexing columns.")
try:
df = dframe.copy()
# ensure parameters are of correct type and length
assert isinstance(columns, (pd.core.index.Index,
list,
np.array)),\
"`columns` must be of type `pandas.core.index.Index` or `list`"
assert isinstance(new_indices,
list),\
"`reorder_indices` must be of type `list`"
assert len(columns) == len(new_indices),\
"Length of `columns` and `reorder_indices` must be equal"
# check for negative values in `new_indices`
if any(idx < 0 for idx in new_indices):
# get a list of the negative values
negatives = [value for value
in new_indices
if value < 0]
# find the index location for each negative value in
# `new_indices`
negative_idx_locations = [new_indices.index(negative)
for negative in negatives]
# zip the lists
negative_zipped = list(zip(negative_idx_locations,
negatives))
# replace the negatives in `new_indices` with their
# absolute position in the index
for idx, negative in negative_zipped:
new_indices[idx] = df.columns.get_loc(df.columns[
negative])
# re-order the index now
# get all columns
all_columns = df.columns
# drop the columns that need to be re-indexed
all_columns = all_columns.drop(columns)
# now re-insert them at the specified locations
zipped_columns = list(zip(new_indices,
columns))
for idx, column in zipped_columns:
all_columns = all_columns.insert(idx,
column)
# re-index the dataframe
df = df.ix[:, all_columns]
print("Successfully re-indexed dataframe.")
except Exception as e:
print(e)
print("Could not re-index columns. Something went wrong.")
return df
νΈμ§: μ¬μ©λ²μ λ€μκ³Ό κ°μ΅λλ€.
# move 'Column_1' to the end, move 'Column_2' to the beginning
df = reindex_columns(dframe=df,
columns=['Column_1', 'Column_2'],
new_indices=[-1, 0])
μΈκΈλμ§ μμ κ·Ήλ¨μ μΈ κ²½μ°(κ°κ° κ³ μ ν μ΄μ ν¬ν¨νλ λ°μ΄ν° νλ μ κ²°ν©)μμ μ΄ λ¬Έμ (0.13.1 ν¬ν¨)κ° λ°μνμ΅λλ€. μ΄ μ΄λ¦μ μμ§ν μ¬ν λΉμ΄ μλνμ§ μμμ΅λλ€.
dat = pd.concat([out_dust, in_dust, in_air, out_air])
dat.columns = [out_dust.columns + in_dust.columns + in_air.columns + out_air.columns]
μ΄μ μ¬μ ν ββμ λ ¬λ©λλ€. λͺ©λ‘μ μ¬μ©νλ©΄ μ€κ°μ ν΄κ²°λμ§λ§:
νΈμ§ : λ무 빨리 λ§νμ΄..
νμ μ‘°μΉ: fwiw, λ¨μΌ κ°μ²΄μ λν .join
νΈμΆλ‘ μ΄ μμλ₯Ό μ μ§ν μ μμ΅λλ€.
df1.join([df2, df3]) # sorts columns
df1.join(df2).join(df3) # column order retained
μ΄ μμ μ§μ μ λν dataFrameμ μμ±ν λ 맀κ°λ³μκ° μμ μ μμ΅λκΉ? μ£Όλ¬Έμ²λΌ=κ±°μ§. μ λ§ κ°μ¬ν©λλ€
μ¬μ μμ λ°μ΄ν° νλ μμ μμ±νλ λμ λ°©κΈ μ΄ λ¬Έμ κ° λ°μνμ΅λλ€. λλ₯Ό μμ ν λλΌκ² νκ³ λ°μ§κ΄μ μ΄μκ³ λ΄ λͺ¨λ λͺ©μ μ μ’μ μμΌ°μ΅λλ€...
μ΄ μ΄λ¦μ λͺ νμ±μ μν΄ μ¬μ©ν΄μΌ νλ©° μλ‘ κ°κΉμ΄ μ΄μ μμΉλ μΌκ΄μ±μ μ μ§νκΈ° μν΄ μ¬μ©μκ° μ‘°μ§μ μΌλ‘ μ ννλ κ²μ λλ€.
@patricktokeeff
join
μ λν ν¬μΈν°λ₯Ό μ£Όμ
μ κ°μ¬ν©λλ€. Series κ°μ²΄μλ ν΄λΉ λ©μλκ° μμΌλ―λ‘ κ²°κ΅ ν¨μλ₯Ό μμ±νκ² λμμ΅λλ€.
def concat_fixed(ndframe_seq, **kwargs):
"""Like pd.concat but fixes the ordering problem.
Converts Series objects to DataFrames to access join method
Use kwargs to pass through to repeated join method
"""
indframe_seq = iter(ndframe_seq)
# Use the first ndframe object as the base for the final
final_df = pd.DataFrame(next(indframe_seq))
for dataframe in indframe_seq:
if isinstance(dataframe, pd.Series):
dataframe = pd.DataFrame(dataframe)
# Iteratively build final table
final_df = final_df.join(dataframe, **kwargs)
return final_df
μ΄μ λν ν¨μ¨μ±μ μ΄λ»μ΅λκΉ?
2017λ
8μ 30μΌ μμμΌ μ€ν 1μ 58λΆ, Bryce Guinta [email protected]
μΌλ€:
@patricktokeeffe https://github.com/patricktokeeffe
κ°μ ν ν¬μΈν°λ₯Ό μ£Όμ μ κ°μ¬ν©λλ€. μλ¦¬μ¦ κ°μ²΄μλ ν΄λΉ λ©μλκ° μμΌλ―λ‘
λλ κ²°κ΅ ν¨μλ₯Ό μμ±νλ€.def concat_fixed(ndframe_seq, **kwargs):
"""pd.concatκ³Ό λΉμ·νμ§λ§ μ£Όλ¬Έ λ¬Έμ λ₯Ό μμ ν©λλ€.Converts Series objects to DataFrames to access join method Use kwargs to pass through to repeated join method """ indframe_seq = iter(ndframe_seq) # Use the first ndframe object as the base for the final final_df = pd.DataFrame(next(indframe_seq)) for dataframe in indframe_seq: if isinstance(dataframe, pd.Series): # Convert Series objects into DataFrames since # series objects do not have a join method dataframe = pd.DataFrame(dataframe) # Iteratively build final table final_df = final_df.join(dataframe, **kwargs) return final_df
β
λΉμ μ΄ λκΈμ λ¬μκΈ° λλ¬Έμ μ΄κ²μ λ°λ κ²μ λλ€.
μ΄ μ΄λ©μΌμ μ§μ λ΅μ₯νκ³ GitHubμμ νμΈνμΈμ.
https://github.com/pandas-dev/pandas/issues/4588#issuecomment-326086636 ,
λλ μ€λ λ μμκ±°
https://github.com/notifications/unsubscribe-auth/AG999MucF-NH5vHuKe-Zczq-jy9ziYkRks5sdbDogaJpZM4A6TeA
.
@MikeTam1021
λλ κ·Έκ²μ atmμΌλ‘ λ²€μΉλ§νΉνμ§ μμ κ²μ΄μ§λ§, λλ κ·Έκ²μ΄ λΉμ μ ndframesμ ν¬κΈ°, κ·Έ μμ ν¨μμΌ κ²μ΄λΌκ³ μκ°ν©λλ€. κ° ndframeμ λν΄ μ λ°μ΄ν° νλ μμ μμ±νλ―λ‘ pd.concat
λ³΄λ€ ν¨μ¬ λ ν¨μ¨μ μ΄λΌκ³ μκ°ν©λλ€.
λ΄ λͺ©μ μλ μ μλνμ§λ§ κ° ndframe(μ½ 10 2 )μ λν΄ μλμ ndframes
(μ½ 10 1 ) λ° λΉκ΅μ μ μ μμ records
λ₯Ό μ¬μ©νκ³ μμ΅λλ€.
λ΄ λͺ©νλ λͺ¨λ ndframeμ μ§μ λ λ μ½λμ λν λ°μ΄ν°κ° ν¬ν¨λμ΄ μμ§ μλλΌλ ν΄λΉ λ μ½λμ μμλ₯Ό μ μ§νλ©΄μ λͺ¨λ λ°μ΄ν° νλ μμ λͺ¨λ λ μ½λλ₯Ό ν¬ν¨νλ κ²μ λλ€.
μ΄ μμλ₯Ό μ΅λν μ μ§νλ κ²μ΄ concat()μ κΈ°λ³Έ λμμ΄ μλ μ΄μ λ₯Ό μ μ μμ΅λλ€.
λ΄ ν΄κ²° λ°©λ²μ Itertools Recipesμ unique_everseen
λ₯Ό μ¬μ©ν©λλ€.
columns = unique_everseen([column for df in dfs for column in df.columns])
df = pd.concat(dfs)[columns]
μ΄ μ€λ λμ μνμ λν μ λ°μ΄νΈκ° μμ΅λκΉ? νμ¬ λ²μ 0.22.0μ μ¬μ©νκ³ μμΌλ©° μ¬μ ν μ μ ν μ루μ μ΄ μλ κ² κ°μ΅λλ€. μ¬κΈ°μμ 미루λ κ²μ΄ κ½€ λ¬Έμ μΈ κ² κ°μ΅λλ€...
λν axis=1
μ κ°μ΄ μ΄μ μ°κ²°ν λ μ μ¬ν λμμ μ°Ύμ μ μμ§λ§ μ¬μ μ λ°μ΄ν° νλ μμ μ λ¬ν λλ§ μ°Ύμ μ μλ€λ μ μ μ£Όλͺ©νκ³ μΆμ΅λλ€.
>>> df4a = DataFrame(columns=['C','B','D','A'], data=np.random.randn(3,4))
>>> df4b = DataFrame(columns=['C','B','D','A'], data=np.random.randn(3,4))
>>> df5 = DataFrame(columns=['C','B','E','D','A'], data=np.random.randn(3, 5))
>>> pd.concat([df4a, df5], axis=1).columns
Index(['C', 'B', 'D', 'A', 'C', 'B', 'E', 'D', 'A'], dtype='object')
>>> pd.concat({'df4a': df4a, 'df4b': df4b}, axis=1).columns.levels
FrozenList([['df4a', 'df4b'], ['C', 'B', 'D', 'A']])
>>> pd.concat({'df4a': df4a, 'df5': df5}, axis=1).columns.levels
FrozenList([['df4a', 'df5'], ['A', 'B', 'C', 'D', 'E']])
μ΄ μ€λ λμ μνμ λν μ λ°μ΄νΈκ° μμ΅λκΉ?
μμ§ μ΄λ € μμ΅λλ€.
μ¬κΈ°μμ 미루λ κ²μ΄ κ½€ λ¬Έμ μΈ κ² κ°μ΅λλ€...
미루λ€? μ°λ¦¬μκ²λ λ§μ λ―Έν΄κ²° λ¬Έμ κ° μμ΅λλ€. λ€μ 릴리μ€μμ μ΄ λ¬Έμ κ° ν΄κ²°λλλ‘ νλ €λ©΄ PRμ μμ±νλ κ²μ΄ κ°μ₯ μ’μ΅λλ€. μμνλ λ° λμμ΄ νμνλ©΄ μλ €μ£Όμμμ€.
@jtratner : 맨 μμ μμμ λͺ ννμ§ μμ κ²½μ° μμλ λ€μκ³Ό κ°μ κ²μΌλ‘ μμν©λλ€.
μ΄κ²μ SQLκ³Ό κ°μ λ€λ₯Έ ν¨ν€μ§λ μΈμ΄μμ μ»μ μ μλ κ²μ λλ€. μμΉ μλ μλ μ λ ¬μ΄ μμ΄μλ μ λ©λλ€. μ¬μ©μκ° μ΄ μ΄λ¦μ μ λ ¬νλ €λ κ²½μ° μλμΌλ‘ μ λ ¬νλλ‘ νμμμ€.
μλ€μ, 2κ°μ§. 1) ν¬λμ μ€μ κ²μ νμν©λλ€! μ¬μ κ³Ό κ°μ λ λ§μ νμ΄μ¬ κΈ°λ³Έ μ νμ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. νμ΄μ¬(λλ λͺ¨λ μΈμ΄)μ SQLλ‘ λ°κΎΈλ €λ μλλ₯Ό μ€λ¨νμμμ€. 2) μ΄κ²μ κΈ°μ μ μΌλ‘ λ²κ·Έκ° μλλλ€. κ·Έκ²μ λ¨μ§ μ½λμ μμΉ μλ ν¨κ³ΌμΌ λΏμ λλ€. ν¨ν€μ§μ 컨ν μ€νΈ μΈλΆμμ μ½κ² 극볡ν μ μμΌλ©° μ¬κΈ°μμ λκ΅°κ°κ° μ€μ€λ‘ ν΄κ²°νμ§ μλ ν μ΄κ²μ΄ μ λ΅μ΄λΌκ³ μκ°ν©λλ€.
@MikeTam1021 ν¨ν€μ§ 컨ν μ€νΈ μΈλΆμμ μ΄λ₯Ό 극볡νλ λ°©λ²μ μ€λͺ ν΄μ£ΌμΈμ. κ°μ¬ ν΄μ.
μ΄ μ€λ λμ μ¬λλ€μ΄ λ Όμν λ΄μ©μ΄ λ°λ‘ μ΄κ²μ΄λΌκ³ νμ ν©λλ€. μμ λ§μ μ’μ μ루μ μ΄ μλν΄μΌ ν©λλ€.
@MikeTam1021 ν¬λλ₯Ό SQLλ‘ λ°κΎΈλ κ²μ μλμ§λ§(μ²κ΅ κΈμ§!) λ€μκ³Ό κ°μ΄ λ λμν μ μμ΅λλ€.
μμΉ μλ μλ μ λ ¬μ΄ μμ΄μλ μ λ©λλ€. μ¬μ©μκ° μ΄ μ΄λ¦μ μ λ ¬νλ €λ κ²½μ° μλμΌλ‘ μ λ ¬νλλ‘ νμμμ€.
DataFramesλ₯Ό μ°κ²°νλ κ²μ "μλ‘ λλν μ°κΈ°"μ κ°μ ν¨κ³Όλ₯Ό κ°μ ΈμΌ νλ©°, κ·Έ μμμ μ λ ¬μ νμ€ν μ΅μ λλΌμμ μμΉμ μλ°ν©λλ€.
λλ λμνλ€. κ·Έλ¬λ©΄ μλ©λλ€. λν μμν μ»΄ν¨ν° κ³Όνμ΄ μλ SQL λ°©μμ μ΄μ λν μμλ₯Ό κ°μ ν©λλ€. λ°μ΄ν°κ° μ΄λμ μλμ§ μ νν μμμΌ ν©λλ€.
λλ μ΄κ²κ³Ό λ€λ₯Έ λ§μ λ¬Έμ λ₯Ό λ°κ²¬ν νμ λ μ΄μ ν¬λλ₯Ό κ±°μ μ¬μ©νμ§ μμ΅λλ€. κ·Έκ²μ λλ₯Ό λ λμ νλ‘κ·Έλλ¨Έλ‘ λ§λ€μλ€.
μ΄κ²μ +1
μ΄κ²μ λλ₯Ό μν΄ μλν©λλ€.
cols = list(df1)+list(df2)
df1 = pd.concat([df1, df2])
df1 = df1.loc[:, cols]
μ΄ ν¨μΉκ° μ΄λ»κ² λ°°ν¬λλμ§μ λν΄ κ°μ리λ₯Ό ν΄μΌ ν©λλ€. concat
μ κΈ°λ₯ μλͺ
μ λμμ λ³κ²½νκ³ μ¬μ©λ²μ λν κ²½κ³ λ₯Ό λμ
νμ΅λλ€. λͺ¨λ λμΌν μ»€λ° λ΄μ μμ΅λλ€.
κ·Έκ²μ λ¬Έμ λ μ°λ¦¬κ° μ¬λ¬ μλ²μμ νλ€λ₯Ό μ¬μ©νκ³ λͺ¨λ μλ²μ νμ λκ°μ νλ€ λ²μ μ΄ μλ€κ³ 보μ₯ν μ μλ€λ κ²μ λλ€. λ°λΌμ μ΄μ μ°λ¦¬λ μ΄μ μ λ³Έ μ μ΄ μλ νλ‘κ·Έλ¨μ κ²½κ³ λ₯Ό 보λ κΈ°μ μ μΈ μ¬μ©μκ° μ€μ΄λ€μκ³ κ²½κ³ κ° λ¬Έμ μ μ§νμΈμ§ νμ€νμ§ μμ΅λλ€.
κ²½κ³ κ° λ°μν μμΉλ₯Ό μ½κ² μλ³ν μ μμ§λ§ μ΄μ λ²μ μ ν¬λλ₯Ό μ€ννλ μλ²μμ νλ‘κ·Έλ¨μ΄ μ€λ¨λ μ μμΌλ―λ‘ μ μλ μ΅μ μ€ νλλ₯Ό μΆκ°ν μ μμ΅λλ€.
μ λ ¬ κΈ°λ₯μ 0.23μ λ£κ³ μ΄ν λ²μ μ κ²½κ³ λ₯Ό μΆκ°νλ€λ©΄ λ μ’μμ κ²μ λλ€. κ·Έ κ³ ν΅μ μκ³ μμ§λ§ μ¬μ©μκ° λͺ¨λ λ°°ν¬λ₯Ό μ΅μ μ½λλ‘ μ¦μ μ λ°μ΄νΈν μ μλ€κ³ κ°μ νλ κ²μ λ€μ λΆμΎν©λλ€.
μ΄ κ²½κ³ μ λν μ μ νν°λ₯Ό μ€μ ν λ€μ
λͺ¨λκ° μ
κ·Έλ μ΄λλλ©΄ λλ‘νμμμ€.
κΈ°λ₯μ μΌλ‘λ λκ°μ£ ?
2018λ 10μ 4μΌ λͺ©μμΌ μ€μ 9:18 DavidEscott [email protected]μμ λ€μκ³Ό κ°μ΄ μΌμ΅λλ€.
μ΄ ν¨μΉκ° μ΄λ»κ² λ°°ν¬λλμ§μ λν΄ κ°μ리λ₯Ό ν΄μΌ ν©λλ€. λΉμ μ
concatμ κΈ°λ₯ μλͺ μ λμμ λ³κ²½νκ³ λμ νμ΅λλ€.
μ¬μ©λ²μ λν κ²½κ³ . λͺ¨λ λμΌν μ»€λ° λ΄μ μμ΅λλ€.λ¬Έμ λ μ°λ¦¬κ° μ¬λ¬ μλ²μμ pandasλ₯Ό μ¬μ©νκ³
λͺ¨λ μλ²μ μμ ν λμΌν λ²μ μ ν¬λκ° μμμ 보μ₯ν©λλ€.
νμμ€. λ°λΌμ μ΄μ νλ‘κ·Έλ¨μμ κ²½κ³ κ° νμλλ κΈ°μ μ¬μ©μκ° μ€μ΄λλλ€.
κ·Έλ€μ μ μ λ³Έ μ μ΄ μμΌλ©° κ²½κ³ κ° κ²½κ³ μ νμμΈμ§ λΆνμ€ν©λλ€.
λ¬Έμ .κ²½κ³ κ° λ°μνλ μμΉλ₯Ό μ½κ² μλ³ν μ μμ§λ§ μΆκ°ν μλ μμ΅λλ€.
μ μλ μ΅μ μ€ νλλ₯Ό μ ννλ©΄ νλ‘κ·Έλ¨μ΄ μ€λ¨λ μ μμΌλ―λ‘
μ΄μ λ²μ μ ν¬λλ₯Ό μ€ννλ μλ².μ λ ¬ κΈ°λ₯μ μΆκ°νλ€λ©΄ λ μ’μμ κ²μ λλ€.
0.23 λ° μΌλΆ μ΄ν λ²μ μ κ²½κ³ λ₯Ό μΆκ°νμ΅λλ€. κ·Έ κ³ ν΅μ μμ§λ§
μ¬μ©μκ° λͺ¨λ νλͺ©μ μ¦μ μ λ°μ΄νΈν μ μλ€κ³ κ°μ νλ κ²μ λ€μ λΆμΎν©λλ€.
μ΅μ μ½λμ λ°°ν¬ν©λλ€.β
μ΄κΈ°/λ«κΈ° μνλ₯Ό μμ νκΈ° λλ¬Έμ μ΄ λ©μμ§κ° νμλ©λλ€.
μ΄ μ΄λ©μΌμ μ§μ λ΅μ₯νκ³ GitHubμμ νμΈνμΈμ.
https://github.com/pandas-dev/pandas/issues/4588#issuecomment-427036391 ,
λλ μ€λ λ μμκ±°
https://github.com/notifications/unsubscribe-auth/ABQHItEhYfv5kqB-R-pDX4zyIh45hF7kks5uhhiWgaJpZM4A6TeA
.
@TomAugspurger μ°λ¦¬ μΈ‘μμ μ΄λ₯Ό μ²λ¦¬ν μ μλ λ€μν λ°©λ²μ΄ μμ΅λλ€. νμ€ν νν°λ§ κ²½κ³ λ νλμ λλ€. κ²½κ³ νν°μ λ©μ»€λμ¦μ΄ μ½κ° λͺ»μκ²ΌκΈ° λλ¬Έμ μ’μ§ μμ΅λλ€...
FutureWarning
νν°λ§ν μ μμ§λ§ ν¬λμμ μ ν κ²½κ³ λ₯Ό λ°μ§ μκ³ λ€λ₯Έ λ³κ²½ μ¬νμ λλ κ²μ
λλ€.μ΄μ¨λ warnings
λͺ¨λμ κ²°ν¨μ νμ€ν λ΄κ° pandas νμ λ°μλ λμ μ μλ κ²μ΄ μλλλ€.
μ°λ¦¬κ° μ½κ² μ κ·Έλ μ΄λν μ μλ μ€λλ μλ²λ₯Ό κ°μ§κ³ μλ κ²λ λΉμ μ μλͺ»μ΄ μλλλ€. κ·Έλμ κ·Έκ²μ΄ μ κ° ν μ μλ λ€λ₯Έ μΌμ λλ€(κ·Έλ₯ λͺ¨λ λ§ν λ°°ν¬λ₯Ό μ κ·Έλ μ΄λνμμμ€). κΆκ·Ήμ μΌλ‘ μ λ κ·Έλ κ² ν΄μΌ νλ©° λ°°ν¬λ₯Ό κΈ΄λ°νκ² μ μ§νλ €κ³ λ Έλ ₯νλ κ²μ΄ μ μ± μμ΄λΌλ κ²μ μκ³ μμ΅λλ€.
μ΄μ μ μ§μ λμ§ μμ APIμ μ΄ μ λ ¬ μ΅μ μ μΆκ°νμ§λ§ λμμ νλ‘κ·Έλλ¨Έμκ² κ²½κ³ λ₯Ό λμ§λ©΄μ μ¬μ©μκ° λ³Ό μ μλ μ΅μ’ λμμ κ°λ₯ν λ³κ²½ μ¬νμ λν΄ μ°λ €νκ³ μλ€λ κ²μ΄ μ κ²λ μ‘°κΈ μ΄μνκ² λ³΄μ λλ€. λ λ€ κ²½κ³ μ μ λ ¬ λμμ μ μλ λ³κ²½μ λ΄ μ± μμ μ¬κ°λκ° λ€λ₯Έ "μ¬μ©μκ° λ³Ό μ μλ λμ"μ ꡬμ±ν©λλ€.
SO μ λν κ΄λ ¨ μ§λ¬Έμ λ΅λ³νμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
μ΄ λμμ μ€μ λ‘ λ§€μ° μμμΉ λͺ»ν κ²μ΄λ©° μ λ μ°μ°ν λ°κ²¬νμ΅λλ€.
μμ§νκ²λ μ΄μ μμκ° μ μ§λ κ²μΌλ‘ μμν μ μμ΅λλ€. λμ μ΄μ΄ μ λ ¬λ©λλ€.
μ΄κ²μ λ€μκ³Ό κ°μ΄ μλ μ΄μ λ€μ μμΈννμ¬ μμ ν μ μμ΅λλ€.
μ¬μ ν μ΄ μλ μ λ ¬μ΄ μνλκ³ λ΄κ° μλ ν λΉνμ±νν μ μλ€λ κ²μ΄ μ§κ΄μ μ΄μ§ μμ κ² κ°μ΅λλ€.