我试图将值插入到数据框中,其中字段是string类型到postgresql数据库中,其中字段是大int类型。
我没有找到如何将它们转换为大int。我在使用 IntegerType 之前没有问题。但是使用这个数据框,演员表导致我负整数
val sparkSession = SparkSession.builder.master("local").appName("spark session example").getOrCreate()
val cabArticleGold = sparkSession.sqlContext.load("jdbc", Map("url" -> "jdbc:oracle:thin:System/maher@//localhost:1521/XE", "dbtable" -> "IPTECH.TMP_ARTCAB")).select("CODEART", "CAB").limit(10)
import sparkSession.sqlContext.implicits._
cabArticleGold.show()
cabArticleGold.withColumn("CAB",'CAB.cast(IntegerType)).foreach(row=>println(row(1)))
232524399
-1613725482
232524423
-1613725465
232524437
-1191331072
3486
-1639094853
232524461
1564177573
Run Code Online (Sandbox Code Playgroud)
任何使用 Big Int 的帮助将不胜感激。我知道scala支持 Big Int,但我该怎么做?
我有麻烦list的lists,以pandas数据帧.
这是我的数据:
list_of_lists = np.array(hazard)
[['13-06-2016' '2.0' '1.0' '3.0' '88.0' '0.0' '72.0' '7.27']
['18-06-2016' '1.0' '0.0' '3.0' '85.5' '0.0' '77.0' '8.05']
['22-06-2016' '3.0' '0.0' '5.0' '91.5' '0.0' '66.0' '7.54']
['26-06-2016' '3.0' '2.0' '4.0' '89.6' '1.0' '74.0' '10.0']
['01-07-2016' '3.0' '0.0' '1.0' '88.9' '0.0' '72.0' '6.75']
['27-08-2016' '7.0' '4.0' '2.0' '81.8' '2.0' '91.0' '8.79']
['01-09-2016' '0.0' '0.0' '1.0' '59.3' '1.0' '46.0' '6.92']
['11-09-2016' '2.0' '1.0' '4.0' '91.7' '0.0' '71.0' '6.84']
['16-09-2016' '0.0' '0.0' '1.0' '81.8' …Run Code Online (Sandbox Code Playgroud) 我有一个DataFrame列表,它们具有相同的列和不同的值.我想从pandas中的一行中的DataFrame列表中删除一些列.
到目前为止,我试过(dfs有数据框列表)
dfs.drop([col for col in ['var1', 'var2'] if col in dfs], axis=1, inplace=True)
Run Code Online (Sandbox Code Playgroud)
和
dfs[dfs.drop([col for col in ['var1', 'var2'] if col in dfs], axis=1, inplace=True)]
Run Code Online (Sandbox Code Playgroud)
两者都给出了同样的错误:
AttributeError:'list'对象没有属性'drop'
type(dfs)
>> list
Run Code Online (Sandbox Code Playgroud)
但是,当我可以dfs使用for循环从列表中循环遍历每个DataFRame时,我可以删除列.
我怎么能在熊猫的列表理解方式中做到这一点?
我有一个熊猫数据帧.我需要将一些列转换为行.数据帧在前3列中每3行具有相同的数据.因此,我将需要6个列,您将在我预期的数据框中看到.我有以下数据帧:
shopCode Product Code Score
111 Apple 123 0.70
111 Apple 456 0.75
111 Apple 789 0.80
222 Orange 142 0.66
222 Orange 136 0.83
222 Orange 623 0.76
Run Code Online (Sandbox Code Playgroud)
我预期的数据框是:
shopCode Product Code1 Code2 Code3 Score1 Score2 Score3
111 Apple 123 456 789 0.70 0.75 0.80
222 Orange 142 136 623 0.66 0.83 0.76
Run Code Online (Sandbox Code Playgroud)
我尝试使用,
df.pivot(index=['shopCode', 'Product'], columns=['Code1', 'Code2', 'Code3', 'Score1', 'Score2', 'Score3'], values=['Code', 'Score'])
但它不起作用.
我有df这样的,
Owner Messages
AAA (YY) Duplicates
AAA Missing Number; (VV) Corrected Value; (YY) Duplicates
AAA (YY) Duplicates
BBB (YY) Duplicates
BBB Missing Measure; Missing Number
Run Code Online (Sandbox Code Playgroud)
当我做这样的正常时groupby,
df_grouped = df.groupby([' Owner', 'Messages']).size().reset_index(name='count')
df_grouped
Run Code Online (Sandbox Code Playgroud)
我按预期得到了这个,
Owner Messages count
0 AAA (YY) Duplicates 2
1 AAA Missing Number; (VV) Corrected Value; (YY) Duplicates 1
2 BBB (YY) Duplicates 1
3 BBB Missing Measure; Missing Number 1
Run Code Online (Sandbox Code Playgroud)
但是,我需要一些东西(所需的输出),就像这个;内部Messages列拆分一样.
Owner Messages count
0 AAA (YY) Duplicates 3 …Run Code Online (Sandbox Code Playgroud) pandas ×4
python ×3
dataframe ×2
group-by ×2
apache-spark ×1
list ×1
numpy ×1
pivot ×1
postgresql ×1
python-3.x ×1
split ×1